From c462ec960bc7790c664aae5c6bbb2d3b57ec8b94 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 16 Oct 2019 06:47:59 -0700 Subject: [PATCH] Eliminate unnessary copy of ByteBuf on ByteToMessageDecoder removal (#9662) Motivation: At the moment we do a ByteBuf.readBytes(...) on removal of the ByteToMessageDecoder if there are any bytes left and forward the returned ByteBuf to the next handler in the pipeline. This is not really needed as we can just forward the cumulation buffer directly and so eliminate the extra memory copy Modifications: Just forward the cumulation buffer directly on removal of the ByteToMessageDecoder Result: Less memory copies --- .../java/io/netty/handler/codec/ByteToMessageDecoder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java index b36186f8c9..6014bca470 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -245,9 +245,7 @@ public abstract class ByteToMessageDecoder extends ChannelHandlerAdapter impleme numReads = 0; int readable = buf.readableBytes(); if (readable > 0) { - ByteBuf bytes = buf.readBytes(readable); - buf.release(); - ctx.fireChannelRead(bytes); + ctx.fireChannelRead(buf); ctx.fireChannelReadComplete(); } else { buf.release();