Repository navigation
Avoid double promise allocation in SslHandler.wrap() - #17382
Merged
normanmaurer merged 1 commit intoSep 10, 2026
Merged
Conversation
franz1981
approved these changes
Sep 3, 2026
franz1981
left a comment
Contributor
There was a problem hiding this comment.
LGTM let's see the CI!
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryBuild PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: 67b60c1 Test FailuresKQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Contributor
|
Could not create auto-port PR. |
Member
|
PR for 5.0: #17413 |
normanmaurer
added a commit
that referenced
this pull request
Sep 10, 2026
Motivation: Production allocation profiling identified `SslHandler.wrap()`'s `ctx.newPromise()` as the source of ~79% of sampled `DefaultChannelPromise` allocations. `wrap()` allocates the promise before checking whether `pendingUnencryptedWrites` contains another entry. After the last entry is consumed, the loop may iterate once more, allocate a `ChannelPromise`, receive null from remove/removeFirst, and immediately discard the promise. <img width="1538" height="110" alt="image" src="https://github.com/user-attachments/assets/e567e5f5-281e-4fcd-8c64-d5e5a320efcd" /> Flow: ``` iteration #1 newPromise() // useful removeFirst() -> buf encrypt buf queue now empty iteration #2 newPromise() // wasted allocation removeFirst() -> null break ``` Modification: Added a guard check `!pendingUnencryptedWrites.isEmpty()` to avoid unnecessary loop iteration. Result: Less garbage in SslHandler for outgoing packets. ``` import io.netty.buffer.ByteBuf; import org.openjdk.jmh.annotations.Benchmark; public class SslHandlerWrapBenchmark extends AbstractSslHandlerThroughputBenchmark { @benchmark public int wrapOneWrite() throws Exception { ByteBuf encrypted = doWrite(1); try { return encrypted.readableBytes(); } finally { encrypted.release(); } } } ``` ``` baseline: 1411.886 B/op patched: 1336.061 B/op delta: 75.825 B/op ``` Co-authored-by: Dmytro Dumanskiy <[email protected]>
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
Production allocation profiling identified
SslHandler.wrap()'sctx.newPromise()as the source of ~79% of sampledDefaultChannelPromiseallocations.wrap()allocates the promise before checking whetherpendingUnencryptedWritescontains another entry. After the last entry is consumed, the loop may iterate once more, allocate aChannelPromise, receive null from remove/removeFirst, and immediately discard the promise.Flow:
Modification:
Added a guard check
!pendingUnencryptedWrites.isEmpty()to avoid unnecessary loop iteration.Result:
Less garbage in SslHandler for outgoing packets.