Skip to content

async: reduce small writes when sending frames - #327

Merged
wllenyj merged 1 commit into
masterfrom
perf-async-frame-coalescing-master
Sep 15, 2026
Merged

wllenyj merged 1 commit into
masterfrom
perf-async-frame-coalescing-master

Conversation

@Tim-Zhang

Copy link
Copy Markdown
Member

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.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@wllenyj wllenyj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wllenyj
wllenyj merged commit 7a1de3f into master Sep 15, 2026
12 checks passed
@wllenyj
wllenyj deleted the perf-async-frame-coalescing-master branch September 15, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants