make delayed sending slightly faster

This commit is contained in:
Eoghanmc22 2021-03-07 20:23:01 -05:00
parent 6f9a92ac76
commit a61034fc1d

View File

@ -163,16 +163,17 @@ public class NettyPlayerConnection extends PlayerConnection {
if (message instanceof FramedPacket) { if (message instanceof FramedPacket) {
final FramedPacket framedPacket = (FramedPacket) message; final FramedPacket framedPacket = (FramedPacket) message;
synchronized (tickBuffer) { synchronized (tickBuffer) {
// Copy is necessary because of cached packets // Duplicate is necessary because of cached packets
tickBuffer.writeBytes(framedPacket.getBody().copy()); tickBuffer.writeBytes(framedPacket.getBody().duplicate());
} }
return; return;
} else if (message instanceof ServerPacket) { } else if (message instanceof ServerPacket) {
final ServerPacket serverPacket = (ServerPacket) message; final ServerPacket serverPacket = (ServerPacket) message;
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, false); final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, true);
synchronized (tickBuffer) { synchronized (tickBuffer) {
tickBuffer.writeBytes(buffer); tickBuffer.writeBytes(buffer);
} }
buffer.release();
return; return;
} else if (message instanceof ByteBuf) { } else if (message instanceof ByteBuf) {
synchronized (tickBuffer) { synchronized (tickBuffer) {
@ -200,9 +201,7 @@ public class NettyPlayerConnection extends PlayerConnection {
synchronized (tickBuffer) { synchronized (tickBuffer) {
final ByteBuf copy = tickBuffer.copy(); final ByteBuf copy = tickBuffer.copy();
ChannelFuture channelFuture = channel.write(new FramedPacket(copy)).addListener(future -> { ChannelFuture channelFuture = channel.write(new FramedPacket(copy)).addListener(future -> copy.release());
copy.release();
});
// Netty debug // Netty debug
if (MinecraftServer.shouldProcessNettyErrors()) { if (MinecraftServer.shouldProcessNettyErrors()) {