async: reduce small writes when sending frames - #327
Merged
Merged
Conversation
Write the header and up to 4 KiB of the frame together, then write any remaining payload directly. Flush after the complete message. Allocate the prefix once and leave the wire format unchanged. Historical E2E P50 observation: +--------------------------------+ | 0.719 ms faster / 1.99% | +--------------------------------+ Sep 7 Guest-side A/B: 30 warm samples per side on the then-current stack. Two rounds passed 90 lifecycles. Gains are not additive; the single-allocation cleanup has not been rebenchmarked. Rust 1.90 unit and sync/async/stream example tests pass. Cover empty and boundary frames, short/zero writes, backpressure and I/O errors. Signed-off-by: Tim Zhang <tim@hyper.sh>
There was a problem hiding this comment.
🟢 Approval recommended
The bounded coalescing preserves wire format and is well covered for boundaries, errors, and backpressure.
Pull request overview
Optimizes asynchronous frame transmission by coalescing headers with a bounded payload prefix.
Changes:
- Adds a shared 4 KiB-bounded frame writer.
- Flushes only after the complete frame.
- Tests write counts, failures, partial writes, and backpressure.
File summaries
| File | Description |
|---|---|
src/proto.rs |
Implements and tests coalesced asynchronous frame writes. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
teawater
approved these changes
Sep 15, 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.
Async frame writes currently emit the 10-byte header in four separate writes and flush it before sending the payload, creating unnecessary small writes.
Combine the header and payload prefix in a buffer capped at 4 KiB, write any remaining payload directly, and flush after the complete frame. This bounds the extra allocation and copying while preserving the wire format. When the writer accepts each buffer in full, a small non-empty frame requires one underlying write instead of five.