Skip to content

sync: reduce write calls and reuse the send buffer - #337

Merged
lifupan merged 1 commit into
masterfrom
perf/sync-frame-coalescing
Oct 8, 2026
Merged

lifupan merged 1 commit into
masterfrom
perf/sync-frame-coalescing

Conversation

@Tim-Zhang

Copy link
Copy Markdown
Member

Port the async send-path optimizations from #327 and #328 to sync.

  • Combine the header and a bounded payload prefix in one write. Small nonempty frames need one transport write instead of two when the buffer is accepted in full.
  • Reuse a prefix buffer of at most 4 KiB in each client/server sender thread. Send the remaining bytes of large payloads directly.
  • Preserve the wire format and existing sender-thread serialization, without adding locks or changing public APIs. Continue handling short writes and return an error on zero writes.
  • Cover frame boundaries, write counts, buffer reuse, write failures, and Unix socket round trips.

Linux validation passed: workspace tests including examples, rustprotobuf/prost unit and security-extension integration tests, formatting, Clippy with warnings denied, and Rust 1.80 sync tests with both codecs. Windows/macOS and RunD end-to-end performance were not tested.

Apply the bounded coalescing used by the async writer in #327 and
the buffer reuse from #328 to both sync sending threads.

Combine the header and payload prefix in a reusable buffer capped at
4 KiB. Write the rest of large payloads directly, preserve short-write
handling, and reject zero writes instead of looping indefinitely.

Add tests for write counts, frame boundaries, reuse, write failures,
and Unix socket round trips.

Signed-off-by: Tim Zhang <[email protected]>
@Tim-Zhang Tim-Zhang changed the title sync: coalesce frame writes and reuse the send buffer sync: reduce write calls and reuse the send buffer Oct 4, 2026
@Tim-Zhang
Tim-Zhang requested a balanced review from Copilot October 8, 2026 08:28

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 implementation preserves wire behavior, handles partial and zero writes correctly, and has focused coverage for the new send path.

0 open findings

What changed in this PR

Ports bounded, reusable send-buffer optimizations to the synchronous transport while preserving framing and short-write handling.

Changes:

  • Coalesces headers with up to 4 KiB of payload.
  • Reuses sender-thread buffers.
  • Adds boundary, failure, reuse, and Unix socket tests.
File Description
src/​sync/​channel.rs Implements optimized frame writes and tests.
src/​sync/​client.rs Reuses a client sender buffer.
src/​sync/​server.rs Reuses each server response buffer.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@lifupan
lifupan merged commit 44890f5 into master Oct 8, 2026
16 checks passed
@lifupan
lifupan deleted the perf/sync-frame-coalescing branch October 8, 2026 08:36
Tim-Zhang added a commit that referenced this pull request Oct 8, 2026
Include the sync send-path optimization from PR #337 in release notes.
Direct migration readers to changelogs and keep the release process
independent of the current release versions.

Signed-off-by: Tim Zhang <[email protected]>
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