From 3d7dba373fff33270a897a7de86f7311952301a2 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 96cd7b3b99..948a71d9a4 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -251,9 +251,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter 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();