Skip to content

Make bulk byte moving in ByteBuf faster#16780

Merged
chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-fix-compression-test
May 9, 2026
Merged

Make bulk byte moving in ByteBuf faster#16780
chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-fix-compression-test

Conversation

@chrisvest

Copy link
Copy Markdown
Member

Motivation:
ByteBuf.getBytes is important for the performance of many bulk byte moving operations.
When the leak detector is enabled, calls like nioBufferCount, nioBuffers, and internalNioBuffer can produce expensive recording calls.

Modification:

  • Unwrap the destination buffer if it is wrapped.
  • Use absolutePut operations on the internal NIO buffer to avoid allocating ByteBuffer instances.

Result:
Bulk byte move operations are faster.
So much so that the DataCompressionHttp2Test.encodingTooBigMessage test no longer fails on a timeout.

@chrisvest chrisvest added this to the 5.0.0.Final milestone May 9, 2026
@chrisvest chrisvest added the needs-cherry-pick-4.2 This PR should be cherry-picked to 4.2 once merged. label May 9, 2026
@chrisvest

Copy link
Copy Markdown
Member Author

This should fix the consistently failing tests we have in the 5.0 branch.

Motivation:
ByteBuf.getBytes is important for the performance of many bulk byte moving operations.
When the leak detector is enabled, calls like `nioBufferCount`, `nioBuffers`, and `internalNioBuffer` can produce expensive recording calls.

Modification:
- Unwrap the destination buffer if it is wrapped.
- Use `absolutePut` operations on the internal NIO buffer to avoid allocating `ByteBuffer` instances.

Result:
Bulk byte move operations are faster.
So much so that the `DataCompressionHttp2Test.encodingTooBigMessage` test no longer fails on a timeout.
@chrisvest chrisvest force-pushed the 5.0-fix-compression-test branch from f0fe918 to 217bf9b Compare May 9, 2026 17:25

@franz1981 franz1981 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! How did you find it? Profiling the CI on failed tests?

@chrisvest

Copy link
Copy Markdown
Member Author

Noticed the unsafe buffer build was not failing. The difference is it runs without leak detection enabled. Enabling that locally the test still passed but took 2 seconds on 5.0, and half a second on 4.2. Profiled the tests and the difference became pretty clear.

@chrisvest chrisvest merged commit 37db5d7 into netty:5.0 May 9, 2026
13 checks passed
@chrisvest chrisvest deleted the 5.0-fix-compression-test branch May 9, 2026 21:44
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.2: #16781

@github-actions github-actions Bot removed the needs-cherry-pick-4.2 This PR should be cherry-picked to 4.2 once merged. label May 9, 2026
normanmaurer pushed a commit that referenced this pull request May 10, 2026
Auto-port of #16780 to 4.2
Cherry-picked commit: 37db5d7

---
Motivation:
ByteBuf.getBytes is important for the performance of many bulk byte
moving operations.
When the leak detector is enabled, calls like `nioBufferCount`,
`nioBuffers`, and `internalNioBuffer` can produce expensive recording
calls.

Modification:
- Unwrap the destination buffer if it is wrapped.
- Use `absolutePut` operations on the internal NIO buffer to avoid
allocating `ByteBuffer` instances.

Result:
Bulk byte move operations are faster.
So much so that the `DataCompressionHttp2Test.encodingTooBigMessage`
test no longer fails on a timeout.

Co-authored-by: Chris Vest <christianvest_hansen@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants