Use allocator when constructing ByteBufHolder sub-types or use Unpool…#9377
Use allocator when constructing ByteBufHolder sub-types or use Unpool…#9377normanmaurer merged 3 commits into4.1from
Conversation
…ed.EMPTY_BUFFER where possible Motivation: In many places Netty uses Unpooled.buffer(0) while should use EMPTY_BUFFER. We can't change this due to back compatibility in the constructors but can use Unpooled.EMPTY_BUFFER in some cases to ensure we not allocate at all. In others we can directly use the allocator either from the Channel / ChannelHandlerContext or the request / response. Modification: - Use Unpooled.EMPTY_BUFFER where possible - Use allocator where possible Result: Fixes #9345 for websockets and http package
|
@doom369 PTAL as an alternative fix. |
| * @param data The data to encode | ||
| * @return An encoded string containing the data | ||
| */ | ||
| @SuppressJava6Requirement(reason = "Guarded with java version check") |
There was a problem hiding this comment.
wow, I didn't know you can do that :)
|
@normanmaurer as cleanup it is ok. However, it doesn't fully fixes #9345. For example, |
|
@doom369 I agree it doesn't 100 % fix all of it but I think for a patch release it is an acceptable tradeoff... I am not sure I understand why using a wrapped buffer is a problem tho. |
|
Hm, you are right. Not sure why I dig into it. |
|
@netty-bot test this please |
|
@doom369 so what you think about this as "first step" ? |
|
@normanmaurer looks good. This PR should fix heap allocation for our flow. If I didn't miss anything. |
|
@doom369 so can you approve ? |
#9377) Motivation: In many places Netty uses Unpooled.buffer(0) while should use EMPTY_BUFFER. We can't change this due to back compatibility in the constructors but can use Unpooled.EMPTY_BUFFER in some cases to ensure we not allocate at all. In others we can directly use the allocator either from the Channel / ChannelHandlerContext or the request / response. Modification: - Use Unpooled.EMPTY_BUFFER where possible - Use allocator where possible Result: Fixes #9345 for websockets and http package
| buffer.release(); | ||
|
|
||
| ByteBuf buffer = ctx.alloc().buffer(buf.length()); | ||
| buffer.writeCharSequence(buf.toString(), CharsetUtil.UTF_8); |
Motivation: After fix #9377 some websocket examples work incorrect Modification: Replace `Unpooled.EMPTY_BUFFER` to `ctx.alloc().buffer(0)` for responses with possible content Result: Examples work
…ed.EMPTY_BUFFER where possible
Motivation:
In many places Netty uses Unpooled.buffer(0) while should use EMPTY_BUFFER. We can't change this due to back compatibility in the constructors but can use Unpooled.EMPTY_BUFFER in some cases to ensure we not allocate at all. In others we can directly use the allocator either from the Channel / ChannelHandlerContext or the request / response.
Modification:
Result:
Fixes #9345 for websockets and http package