Reduce allocations for chunk packet writing

This commit is contained in:
TheMode 2021-08-26 10:55:56 +02:00
parent 024f8d36bd
commit af82bf1236
2 changed files with 7 additions and 2 deletions

View File

@ -33,7 +33,6 @@ public class ChunkDataPacket implements ServerPacket {
public Map<Integer, Block> 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();

View File

@ -45,6 +45,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: