Skip to content

Remove measured redundant protocol buffering - #504

Merged
kixelated merged 5 commits into
mainfrom
quest/a2/protocol-buffering
Nov 8, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/a2/protocol-buffering

Conversation

@kixelated

@kixelated kixelated commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

CONNECT and SETTINGS encoding previously built temporary payloads and copied them into an outer frame buffer. Measure the payload length first, validate CONNECT before writing, and encode directly into the destination. Async writes reserve exactly one final frame buffer. Plain QPACK strings copy directly into their owned storage; Huffman decoding borrows contiguous input and coalesces fragmented input once for the existing decoder.

Closes #169.

Measurements

Ran the same nix develop --command cargo bench -p web-transport-proto --bench buffering harness before implementation on base 7cc85bd28dabca12e9a7330cddc525d884066758 and after, on x86_64 Linux with Rust 1.94.0, bytes 1.12.1 and Tokio 1.54.1. The CSV emits exact allocation totals and iteration counts; this table reports averages rounded to three decimal places over 256 operations with fixture and runtime setup excluded. encode writes into preallocated caller storage; write uses a sink accepting seven bytes at a time; decode uses a borrowed slice; read uses a cursor over the same wire bytes. Each cell is allocations / reallocations per operation, including owned decoded headers.

Path Wire bytes Before After
CONNECT request, no ordinary fields: encode 89 18 / 5 16 / 1
same: write 89 19 / 6 17 / 1
same: decode 89 26 / 2 20 / 2
same: read 89 27 / 2 21 / 2
CONNECT request, 8 fields x 128-byte values: encode 1217 35 / 8.863 33 / 1
same: write 1217 36 / 9.852 34 / 1
same: decode 1217 78 / 3 56 / 3
same: read 1217 79 / 3 57 / 3
CONNECT request, 1 x 12000-byte value: encode 12103 20 / 6.441 18 / 1
same: write 12103 21 / 7.383 19 / 1
same: decode 12103 34 / 2 26 / 2
same: read 12103 35 / 2 27 / 2
CONNECT response: encode 62 10 / 2.445 8 / 0
same: write 62 11 / 3.434 9 / 0
same: decode 62 13 / 0 9 / 0
same: read 62 14 / 0 10 / 0
Huffman response, 1024 decoded 'a' bytes: decode 656 8 / 7 5 / 7
same: read 656 9 / 7 6 / 7
WebTransport SETTINGS: encode 36 1 / 3 0 / 0
same: write 36 2 / 4 1 / 0
same: decode 36 2 / 0 2 / 0
same: read 36 3 / 0 3 / 0
SETTINGS plus 64 entries: encode 421 1 / 6 0 / 0
same: write 421 2 / 7 1 / 0
same: decode 421 6 / 0 6 / 0
same: read 421 7 / 0 7 / 0

The largest put_slice into caller storage changes from the complete staged payload to individual field data: 86 -> 22 bytes for the small request, 1214 -> 128 for eight fields, 12100 -> 12000 for the large request, 60 -> 28 for the response, and 33/417 -> 8 for SETTINGS. This observes the encode boundary, not every internal memory copy. The removed staging copy is one payload-sized copy per encode/write. Plain strings eliminate the intermediate copy_to_bytes allocation/copy on borrowed or fragmented input; a contiguous owning Bytes input retains its existing necessary owned-string allocations. Requested allocation bytes for the eight-field decode drop from 7476 to 6308, and for Huffman decode from 3554 to 2268.

Async reads measure exactly one payload allocation beyond synchronous decoding, so their bounded payload buffering is retained. SETTINGS read/decode has no measured redundant buffer and stays unchanged. Timings include instrumentation, vary with map order and short-run noise, and support no throughput claim or acceptance threshold. A sequential diagnostic measured the Huffman fixture at 2.843 us/decode on base and 3.055 us/decode on the final implementation. Extracting the shared loop without an inline hint measured 4.191 us; keeping the loop inline avoided that larger regression while retaining the allocation savings.

Decisions and compatibility

  • Use private length measurement and a private validated HeadersFrame shared by request/response encode/write. Keep canonical minimal-width lengths and existing owned decoded headers. A private list of QPACK wire pieces shares representation and prefix choices between sizing and encoding. No new dependency or public API, version bump, or wire compatibility change.
  • Replace the temporary pseudo-header sorting vector with two stable iteration passes. Preserve field order within each category, including repeated fields when combined with the response-header work.
  • Keep 16 KiB CONNECT encoded/decoded limits, 64 KiB other-frame limits, error-before-write behavior, partial I/O and exact frame consumption. No parser or read-buffer redesign.
  • The benchmark runs through the existing all-targets test setup. Regression tests cover QPACK prefix-width boundaries, static/literal representations, one-byte Buf chunks, Huffman padding/budget errors with identical string consumption on contiguous and fragmented inputs, QUIC varint widths, pending/fragmented async I/O and a real following capsule.

Integration with response headers

This PR stays independent of moq-dev/web-transport#499, reviewed at 6b1f4e28b9822cbb907839d2d5141fa5f5027ca1. When integrating overlapping connect.rs edits, keep that PR's ordinary-header validation, append calls, repeated-field ownership and structured rejection semantics inside request/response header preparation, now named frame(). Keep its QPACK Vec field storage: the size calculation counts every field line and the two-pass encoder retains repeated-name order. Its added tests calling the old encode_headers_frame(&fields, ...) helper should construct the private HeadersFrame from those fields and encode it. No response/rejection header implementation is imported here.

Validation

Passed using the Nix development shell through quest gate:

  • just fix
  • cargo test -p web-transport-proto --all-targets: 72 unit tests, two new framing tests and the benchmark target
  • just check: native/WASM checks, clippy, formatting, feature powersets, both FFI TLS providers and JavaScript/TypeScript checks
  • just test: native/WASM workspace tests and doctests, QMux unit/interop tests and Node polyfill build/tests
  • Installed quest check --base origin/main: 41 documents valid

The baseline and final benchmark use the same harness. No repository harness changes, suppressed failures or widened timeouts.

Review

Claude Code (claude-opus-5-5, medium effort), round 3, reviewed final head adaf0ce6841de2ba3b26c6545d0ad8b92092c97a against origin/main (7cc85bd28dabca12e9a7330cddc525d884066758) with no findings.

All three round 1 findings are fixed: exact benchmark totals replace truncated averages; contiguous Huffman input is borrowed with padding/budget/consumption regressions; and shared private wire pieces select QPACK representations and prefix widths for both size measurement and output. Round 2 had no findings. The subsequent one-line inline hint was measured, validated and reviewed again on this final head.

Follow-ups

None identified within the buffering scope.

(Written by GPT-6.1 Sol with xhigh)

kixelated and others added 5 commits November 7, 2026 05:25
Measure frame lengths before encoding and reserve final async buffers. Retain bounded reads and validate framing across partial I/O and prefix-width boundaries.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
Remove QPACK payload staging, pseudo-header sorting storage, and duplicate string copies. Add allocation/copy benchmarks and framing regressions while preserving owned decoded headers and bounded reads.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
Preserve Huffman string consumption on errors and cover fragmented input. Report exact benchmark counter totals so occasional reallocations remain visible.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
Preserve optimizer visibility for the shared loop; measured separately against the base and non-inlined versions.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>

Copy link
Copy Markdown
Collaborator Author

Design change: share each QPACK field's wire pieces between size calculation and encoding so representation selection and prefix widths have one definition. Decode contiguous Huffman input in place and coalesce fragmented input for the existing decoder, preserving full encoded-string consumption on errors. The benchmark emits exact allocation totals and iteration counts. An inline hint keeps the extracted Huffman loop near its prior timing while retaining the measured allocation savings. These refinements passed the final local review and repository checks; the PR body records the measurements and integration notes.

(Written by GPT-6.1 Sol with xhigh)

@kixelated
kixelated marked this pull request as ready for review November 7, 2026 13:55
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47bdf546-1345-467c-9395-5232b159b234
Commits

Reviewing files that changed from the base of the PR and between 7cc85bd and adaf0ce.

Files selected for processing: 10

  • quest/a2/README.md
  • quest/a2/protocol-buffering.md
  • rs/web-transport-proto/Cargo.toml
  • rs/web-transport-proto/README.md
  • rs/web-transport-proto/benches/buffering.rs
  • rs/web-transport-proto/src/connect.rs
  • rs/web-transport-proto/src/huffman.rs
  • rs/web-transport-proto/src/qpack.rs
  • rs/web-transport-proto/src/settings.rs
  • rs/web-transport-proto/tests/framing.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T13:56:22.852718Z adaf0ce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary: landing head adaf0ce by squash (the only method this repository allows).

  • CI: 5/5 required checks passed on this head; merge state clean against main (7cc85bd).
  • Reviews: Codex completed a review of this head with no findings; no unresolved threads. CodeRabbit was rate-limited and did not review.
  • quest check --base origin/main on the head passed (41 documents); the PR deletes the finished quest/a2/protocol-buffering.md and its link.
  • No changes were made during merge and no decisions were outstanding.

(Written by Claude Opus 5.5)

@kixelated
kixelated merged commit de6e779 into main Nov 8, 2026
5 checks passed
@kixelated
kixelated deleted the quest/a2/protocol-buffering branch November 8, 2026 17:02
@moq-bot moq-bot Bot mentioned this pull request Nov 8, 2026
kixelated added a commit that referenced this pull request Nov 8, 2026
Port the response-header tests onto the measured HeadersFrame encoder from #504,
use qpack append in main's measured-section test, drop the removed Quinn crypto
feature gates from the response-header test (#488), and use
ConnectResponse::default() in the router client test (#497).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web-transport-proto: Have the read() and write() methods avoid copying to an intermediate buffer

1 participant