From 622f632989fbe52cb8c5cd20b9990bdf92a8cdaf Mon Sep 17 00:00:00 2001 From: themode Date: Thu, 25 Mar 2021 16:51:36 +0100 Subject: [PATCH] Use heap buffer for short lived packets --- .../minestom/server/network/player/NettyPlayerConnection.java | 2 +- src/main/java/net/minestom/server/utils/PacketUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java index 053fe23a0..7581d3160 100644 --- a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java +++ b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java @@ -176,7 +176,7 @@ public class NettyPlayerConnection extends PlayerConnection { } else if (message instanceof ServerPacket) { final ServerPacket serverPacket = (ServerPacket) message; synchronized (tickBuffer) { - final ByteBuf framedPacket = PacketUtils.createFramedPacket(serverPacket, true); + final ByteBuf framedPacket = PacketUtils.createFramedPacket(serverPacket, false); tickBuffer.writeBytes(framedPacket); framedPacket.release(); } diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index d8af05b94..f9c839bed 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -214,14 +214,14 @@ public final class PacketUtils { packetBuf = compressedBuf; } else { // Packet too small - ByteBuf uncompressedLengthBuffer = directBuffer ? BufUtils.getBuffer(true, 1) : Unpooled.buffer(); + ByteBuf uncompressedLengthBuffer = Unpooled.buffer(); Utils.writeVarIntBuf(uncompressedLengthBuffer, 0); packetBuf = Unpooled.wrappedBuffer(uncompressedLengthBuffer, packetBuf); } } // 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()); return Unpooled.wrappedBuffer(packetLengthBuffer, packetBuf);