From d4e51f562c346fa1e2c8caa4b847ae16013dab0f Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 2 Sep 2021 18:44:50 +0200 Subject: [PATCH] Remove threadlocal buffer cache in ChunkDataPacket Signed-off-by: TheMode --- .../network/packet/server/play/ChunkDataPacket.java | 3 +-- src/main/java/net/minestom/server/utils/PacketUtils.java | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java index 2d552b831..5cd391611 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java @@ -33,7 +33,6 @@ public class ChunkDataPacket implements ServerPacket { public Map entries = new HashMap<>(); private static final byte CHUNK_SECTION_COUNT = 16; - private static final PacketUtils.LocalCache BLOCK_CACHE = PacketUtils.LocalCache.get("chunk-block-cache", 262_144); /** * Heightmaps NBT, as read from raw packet data. @@ -49,7 +48,7 @@ public class ChunkDataPacket implements ServerPacket { writer.writeInt(chunkX); writer.writeInt(chunkZ); - ByteBuffer blocks = BLOCK_CACHE.get(); + ByteBuffer blocks = PacketUtils.localBuffer(); Int2LongRBTreeMap maskMap = new Int2LongRBTreeMap(); diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index b8c4e93be..12de838ff 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -38,6 +38,12 @@ public final class PacketUtils { private PacketUtils() { } + @ApiStatus.Internal + @ApiStatus.Experimental + public static ByteBuffer localBuffer() { + return COMPRESSION_CACHE.get(); + } + /** * Sends a packet to an audience. This method performs the following steps in the * following order: @@ -200,7 +206,7 @@ public final class PacketUtils { @ApiStatus.Internal public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) { final var temp = PacketUtils.createFramedPacket(packet); - final var buffer= ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer(); + final var buffer = ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer(); return new FramedPacket(packet.getId(), buffer, packet); }