Repository navigation
Write and read HTTP/2 frames with fewer copies and writes - #1487
Merged
Merged
Conversation
Every frame the client or server wrote went through a fresh IOBuffer: the payload was copied into a tuple, the header into its own vector, both into the IOBuffer, and out with take!. Each flow-control credit became two separately locked writes, one per WINDOW_UPDATE frame, and every frame read allocated a 9-byte header vector. A 1 MiB HTTP/2 upload made about 2,800 allocations in client and server together. Frames are now serialized into one exact-size vector, a credit's connection and stream WINDOW_UPDATE frames go out in one write, and frame headers and WINDOW_UPDATE frames already buffered in the connection reader are parsed in place. The bytes on the wire are unchanged. The same upload now makes about 1,160 allocations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1487 +/- ##
==========================================
+ Coverage 91.55% 91.61% +0.05%
==========================================
Files 31 31
Lines 12972 13081 +109
==========================================
+ Hits 11877 11984 +107
- Misses 1095 1097 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # CHANGELOG.md # src/http2_server.jl
quinnj
referenced
this pull request
Oct 22, 2026
URIs 1.7.2 rejects "http://[::1]evil.com/" when building the URI, so the test now accepts either rejection; with older URIs the URI still parses and HTTP must throw ArgumentError. Test-only change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Every HTTP/2 frame the client or server wrote went through a fresh
IOBuffer:_serialize_framecopied the payload, the 9-byte header went into its own vector, both were written into theIOBuffer, andtake!produced the bytes to send. Returning flow-control credit wrote two WINDOW_UPDATE frames (connection and stream) as two separately locked writes, after everybody_read!. Reading allocated a 9-byte vector for each frame header and a 4-byte payload for each WINDOW_UPDATE.Now:
_frame_bytes), without the payload copy orIOBuffer, andwrite_frame!writes it in one call._window_update_frames), on both client and server._header_block_framesno longer copies a header block that fits in one frame; every caller writes the frame immediately.The bytes on the wire are unchanged, in the same order.
Whole-process allocations for a 1 MiB HTTP/2 upload (client and server in one process,
--threads=4,1, minimum of 5):Julia 1.12, in-process round trips (latency: median and min–max of per-run medians over 4 interleaved runs per build, heavily loaded machine):
Reading a buffered WINDOW_UPDATE frame allocates 16 bytes (the returned frame) instead of 144–160 on Julia 1.10 through 1.13.
Verification
test/http2_frame_tests.jl:_window_update_framesproduces the same bytes aswrite_frame!of the two frames; frames read through a 4-byte_ConnReaderbuffer (headers and payloads split across reads) and through a prefilled one parse the same; reading a buffered WINDOW_UPDATE allocates at most 64 bytes (144–160 on master).http2_frame_tests.jl,http2_server_tests.jl,http2_client_tests.jl,http2_settings_tests.jl,http2_refused_stream_retry_tests.jlpass on 1.12. Rebased on Fix HTTP/2 server receive-window accounting #1452, whose receive-window accounting in_send_h2_server_window_updates!is kept. The full suite with this and my other open allocation changes combined passes on 1.12 excepttrim_compile_tests.jl, which fails the same way on master locally (a verifier warning insideReseau.TLS._read_some!).Review
_serialize_framehas one caller,_frame_bytes, which copies the payload into the new vector, so returning the frame's own payload vector is safe._ConnReaderwith the whole header (9 bytes) or WINDOW_UPDATE payload (4 bytes) buffered; otherwise the generic path runs. The fast WINDOW_UPDATE path applies the same length, reserved-bit mask, and zero-increment checks and errors as the generic one.🤖 Generated with Claude Code