Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Remove another memory copy with compression.
I considered using composite byte buffers but they would have added GC overhead and would've been incompatible with any native code we added unless special care was taken.
Dieser Commit ist enthalten in:
Ursprung
44932cfddb
Commit
0191b74840
@ -17,22 +17,14 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
|
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
|
||||||
if (msg.readableBytes() <= threshold) {
|
int uncompressed = msg.readableBytes();
|
||||||
|
if (uncompressed <= threshold) {
|
||||||
// Under the threshold, there is nothing to do.
|
// Under the threshold, there is nothing to do.
|
||||||
ProtocolUtils.writeVarInt(out, 0);
|
ProtocolUtils.writeVarInt(out, 0);
|
||||||
out.writeBytes(msg);
|
out.writeBytes(msg);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
// in other words, see if a plain 8KiB buffer fits us well
|
|
||||||
ByteBuf compressedBuffer = ctx.alloc().buffer(8192);
|
|
||||||
try {
|
|
||||||
int uncompressed = msg.readableBytes();
|
|
||||||
compressor.deflate(msg, compressedBuffer);
|
|
||||||
ProtocolUtils.writeVarInt(out, uncompressed);
|
ProtocolUtils.writeVarInt(out, uncompressed);
|
||||||
out.writeBytes(compressedBuffer);
|
compressor.deflate(msg, out);
|
||||||
} finally {
|
|
||||||
compressedBuffer.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||||
if (in.readableBytes() < 1) {
|
if (!in.isReadable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren