mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
Use heap buffer for short lived packets
This commit is contained in:
parent
b3655ad82d
commit
622f632989
@ -176,7 +176,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
} else if (message instanceof ServerPacket) {
|
} else if (message instanceof ServerPacket) {
|
||||||
final ServerPacket serverPacket = (ServerPacket) message;
|
final ServerPacket serverPacket = (ServerPacket) message;
|
||||||
synchronized (tickBuffer) {
|
synchronized (tickBuffer) {
|
||||||
final ByteBuf framedPacket = PacketUtils.createFramedPacket(serverPacket, true);
|
final ByteBuf framedPacket = PacketUtils.createFramedPacket(serverPacket, false);
|
||||||
tickBuffer.writeBytes(framedPacket);
|
tickBuffer.writeBytes(framedPacket);
|
||||||
framedPacket.release();
|
framedPacket.release();
|
||||||
}
|
}
|
||||||
|
@ -214,14 +214,14 @@ public final class PacketUtils {
|
|||||||
packetBuf = compressedBuf;
|
packetBuf = compressedBuf;
|
||||||
} else {
|
} else {
|
||||||
// Packet too small
|
// Packet too small
|
||||||
ByteBuf uncompressedLengthBuffer = directBuffer ? BufUtils.getBuffer(true, 1) : Unpooled.buffer();
|
ByteBuf uncompressedLengthBuffer = Unpooled.buffer();
|
||||||
Utils.writeVarIntBuf(uncompressedLengthBuffer, 0);
|
Utils.writeVarIntBuf(uncompressedLengthBuffer, 0);
|
||||||
packetBuf = Unpooled.wrappedBuffer(uncompressedLengthBuffer, packetBuf);
|
packetBuf = Unpooled.wrappedBuffer(uncompressedLengthBuffer, packetBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the final length of the packet
|
// Write the final length of the packet
|
||||||
ByteBuf packetLengthBuffer = directBuffer ? BufUtils.getBuffer(true, 5) : Unpooled.buffer();
|
ByteBuf packetLengthBuffer = Unpooled.buffer();
|
||||||
Utils.writeVarIntBuf(packetLengthBuffer, packetBuf.readableBytes());
|
Utils.writeVarIntBuf(packetLengthBuffer, packetBuf.readableBytes());
|
||||||
|
|
||||||
return Unpooled.wrappedBuffer(packetLengthBuffer, packetBuf);
|
return Unpooled.wrappedBuffer(packetLengthBuffer, packetBuf);
|
||||||
|
Loading…
Reference in New Issue
Block a user