Repository navigation
perf(mux-h1): reuse the write pass IoSlice vector across passes - #1582
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 26, 2026 17:23
FlorentinDUBOIS
force-pushed
the
perf/h1-write-iovec-no-alloc
branch
from
September 26, 2026 17:42
20c900f to
d6b848e
Compare
ConnectionH1::writable built a fresh Vec<IoSlice> on every write pass, in both directions: one allocation on the first descriptor, then one realloc per doubling. An H1 header block is dozens of Store blocks, so intentrace shows 45 descriptors in the writev(2) of a curl request and 32 in that of a python3 -m http.server response. The vector is now a pub(super) io_slices field of ConnectionH1, set only by its two constructors, and writable fills and discharges it through h2_transmit::gather and h2_transmit::confirm, the pair the H2 write pass already uses, instead of its own loop. Only the capacity survives a pass: gather clears the vector on entry and confirm clears it before Kawa::consume. Between the two, writable only writes, copies the accepted bytes into the replay capture (retry_buffer, never kawa) and pushes a debug event; its one early return there is taken only when the vector is empty. h1.rs gains its first unsafe block, the gather call under that function's existing safety contract. No new unsafe code and no new dependency. Measured with the shared test_allocations counter, one warm 16-block pass: 3 -> 0 allocations on the response and on the request side, in debug and release. Release build, one worker, H1 listener, python backend, intentrace -p <worker> --trace writev: 200 writev(2) before and after for 100 sequential connections and for 100 requests on one connection, with the same descriptor counts per call. Closes #1580 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
perf/h1-write-iovec-no-alloc
branch
from
September 26, 2026 18:44
d6b848e to
e357b9d
Compare
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.
Closes #1580
What
ConnectionH1::writablebuilt a freshVec<IoSlice>on every write pass, in both directions (response to the frontend, request to the backend). It allocated on the first descriptor and then made onereallocper doubling. An H1 header block is dozens ofStoreblocks, one per status-line piece and four per header, sointentraceshows 45 descriptors in thewritev(2)of acurlrequest and 32 in that of apython3 -m http.serverresponse.This is #1571 on the H1 side, and #1578's mechanism is already shared.
h2_transmit::gatherandh2_transmit::confirmare generic overKawa<T: AsBuffer>, andgatherdoes exactly what the H1 loop did. So the change reuses that pair and adds no new abstraction:ConnectionH1gets anio_slices: Vec<IoSlice<'static>>field. It ispub(super)only because the two constructors live inmux/connection.rs, likepeer_address.writablereplaces its hand-written loop and itsqueuedsum withh2_transmit::gather, and itskawa.consume(size)withh2_transmit::confirm.Safety argument
Only the vector's capacity survives a pass, never a descriptor:
gatherclears the vector on entry, andconfirmclears it beforeKawa::consume.writablemakes the vectored write, which reborrows the descriptors and cannot retain them. It then copies the accepted bytes into the replay capture, which reads the descriptors and writes toretry_buffer, never tokawa, and pushes one debug event.SAFETYcomment describes this shape rather than copying H2's.returninside the window is taken only when the vector is empty.IoSlicehas noDrop), and the nextgatherclears them before anything could read them.h1.rsgains its firstunsafeblock, which is the call togatherunder that function's existing# Safetycontract. There is no newunsafecode and no new dependency. The docs ofh2_transmit.rsanddoc/h2_mux_internals.mdnow name the second caller.Measurements
Unit tests.
a_warm_h1_response_write_pass_allocates_nothing(Position::Server) anda_warm_h1_request_write_pass_allocates_nothing(Position::Client, freshly dialled, so the replay capture stays off) each count the allocations of one warmwritablepass. They use the sharedcrate::test_allocationscounter; no new#[global_allocator]. The pass writes 16Storeblocks to a live loopback peer.cargo test --release, responsecargo test --release, requestcargo test(debug), each sideOn a3e72a3, one block per pass costs 1 allocation. With 16 blocks, the 3 allocations are one
allocand tworeallocs (4 → 8 → 16). To see the tests fail, givewritablea per-pass local vector in place ofself.io_slices, as their doc comments describe. That measuresleft: 3, right: 0in both profiles.Release binary, built with
--no-default-features --features crypto-ring,opentelemetry,splice,simd. The setup is one worker, an H1 listener, and apython3 -m http.serverbackend. The counts come fromintentrace -p <worker> --trace writev, with ANSI codes stripped and lines anchored on the syscall-name field:writev(2), 100 sequential connectionswritev(2), 100 requests on onecurlconnectionwritev(2)The
writev(2)count does not change: the change moves where the descriptors live, not how many go into each call.Rebased on #1578
Rebased on
b5169d44, which includes #1578. The two callers ofgathernow share one "two production callers" paragraph in its docs, and the H1 field sits beside H2's privateio_slicesfield.Checks
The following all exit 0:
cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simdcargo +nightly fmt --all -- --check--all-targets -- -D warningscargo test -p sozu-lib(1161),-p sozu(226),-p sozu-command-lib(185)cargo test -p sozu-e2e -- --skip tests::fuzz_tests::(449)RUSTFLAGS="--cfg tokio_unstable"check_doc_citations.py--self-test,--root .,--base b5169d44, and--audit. Fourh1.rscitations in the twoLIFECYCLE.mdfiles are re-anchored to the same text in the same function.RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --lockedSigned-off-by: Florentin Dubois [email protected]