Remove memory copy when extract frame in LengthFieldBasedFrameDecoder
Motivation: We are currently doing a memory cop to extract the frame in LengthFieldBasedFrameDecoder which can be eliminated. Modifications: Use buffer.slice(...).retain() to eliminate the memory copy. Result: Better performance.
This commit is contained in:
parent
c4d69e982b
commit
891be30a28
@ -491,9 +491,7 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
|
||||
* is overridden to avoid memory copy.
|
||||
*/
|
||||
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
|
||||
ByteBuf frame = ctx.alloc().buffer(length);
|
||||
frame.writeBytes(buffer, index, length);
|
||||
return frame;
|
||||
return buffer.slice(index, length).retain();
|
||||
}
|
||||
|
||||
private void fail(long frameLength) {
|
||||
|
Loading…
Reference in New Issue
Block a user