Optimize HTTP2ToHTTP1 client codec to reduce empty data frames#535
Merged
fabianfett merged 7 commits intomainfrom Feb 10, 2026
Merged
Optimize HTTP2ToHTTP1 client codec to reduce empty data frames#535fabianfett merged 7 commits intomainfrom
fabianfett merged 7 commits intomainfrom
Conversation
The codec now caches the most recent outbound frame and only writes it on flush or when receiving `.end`. This lets us set `endStream=true` on the final data or headers frame instead of sending a separate empty data frame. Changes: - Introduced `PendingFrameWrite` to cache frame payload and promise - Modified `processOutboundData` to return optional frames instead of writing immediately - Added `flush()` method to both client codecs to handle cached writes - Promise merging ensures correct completion notification when combining frames
glbrntt
reviewed
Feb 10, 2026
dev/alloc-limits-from-test-output
Outdated
| @@ -0,0 +1,110 @@ | |||
| #!/bin/bash | |||
Contributor
There was a problem hiding this comment.
Do we need to duplicate these two scripts or can they be run from the NIO repo? These scripts do get updated from time to time so not having them spread out would be great.
| return (.init(.data(data), flushPromise), nil) | ||
|
|
||
| case (.data(let data), .some(let trailers)): | ||
| let trailers = self.makeH2TrailerFramePayload(trailers) |
Contributor
There was a problem hiding this comment.
nit, can you avoid shadowing trailers here?
Comment on lines
+199
to
+201
| // We only need to merge, if there is an outstanding frame write. Therefore we can bang | ||
| // the frame write here. | ||
| switch (self.pendingFrameWrite!.promise, endPromise) { |
Contributor
There was a problem hiding this comment.
I don't like that the ! is hidden away in this function, it puts the onus on the caller to know that self.pendingFrameWrite isn't nil.
FWIW setOrCascade might be helpful here https://github.com/apple/swift-nio/blob/db01d879426d6d99b2c2d4a6e802a4a0c6e8de2a/Sources/NIOCore/EventLoopFuture.swift#L2133-L2153
Member
Author
There was a problem hiding this comment.
uses setOrCascade now.
74df33e to
bcbe385
Compare
glbrntt
approved these changes
Feb 10, 2026
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.
The codec now caches the most recent outbound frame and only writes it on flush or when receiving
.end. This lets us setendStream=trueon the final data or headers frame instead of sending a separate empty data frame.Changes:
PendingFrameWriteto cache frame payload and promiseprocessOutboundDatato return optional frames instead of writing immediatelyflush()method to both client codecs to handle cached writes