Skip to content

perf: reduce syscalls with writev, BufReader, and message coalescing - #2348

Merged
oferchen merged 1 commit into
masterfrom
perf/syscall-optimization
Feb 19, 2026
Merged

oferchen merged 1 commit into
masterfrom
perf/syscall-optimization

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • write_vectored: Combine buffer flush + large chunk into a single writev syscall in ReusableBufWriter, eliminating double-write per file
  • Socket-level BufReader (64KB): Batch 4-byte multiplex header reads with payload reads into fewer recvfrom syscalls (37K → 6.4K, -83%)
  • WholeFile message coalescing: Single-chunk files send one WholeFile channel message instead of Begin + Chunk + Commit (3 sends → 1), reducing futex overhead

Benchmark Results (daemon, 10K files, 422MB)

Benchmark Upstream rsync HEAD (before) This PR vs upstream
Initial copy 903ms 600ms 555ms 1.63x faster
Incremental 137ms 117ms 76ms 1.82x faster

Syscall Comparison (strace -f -c, initial copy)

Syscall HEAD This PR Change
recvfrom 37,421 6,440 -83%
Total 164,538 136,156 -17%

Test Plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • cargo nextest run --workspace --all-features — 21,725 tests pass
  • Functional alignment verified: file counts, mtimes, sizes, permissions match upstream
  • Daemon benchmark (initial + incremental)
  • SSH benchmark (initial + incremental)
  • strace syscall analysis

Three optimizations targeting I/O syscall overhead:

1. write_vectored in ReusableBufWriter: combine buffer flush + large
   chunk into a single writev syscall (was 2 write calls per file)

2. Socket-level BufReader (64KB): batch 4-byte multiplex header reads
   with payload reads into fewer recvfrom syscalls (-83%, 37K → 6.4K)

3. WholeFile message coalescing: single-chunk files send one channel
   message instead of Begin+Chunk+Commit (3 sends → 1), reducing
   futex overhead for small files

Daemon benchmark (10K files, 422MB):
- Initial copy: 1.63x faster than upstream rsync (555ms vs 903ms)
- Incremental:  1.82x faster than upstream rsync (76ms vs 137ms)
- Total syscalls: 136K (was 164K, -17%)
@oferchen
oferchen merged commit d4cf431 into master Feb 19, 2026
9 checks passed
@oferchen
oferchen deleted the perf/syscall-optimization branch February 19, 2026 01:51
oferchen added a commit that referenced this pull request May 1, 2026
perf: reduce syscalls with writev, BufReader, and message coalescing
oferchen added a commit that referenced this pull request May 5, 2026
perf: reduce syscalls with writev, BufReader, and message coalescing
oferchen added a commit that referenced this pull request May 18, 2026
Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request May 18, 2026
Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request May 18, 2026
Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request May 18, 2026
#4408)

Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request May 18, 2026
#4408)

Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request May 18, 2026
#4408)

Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
oferchen added a commit that referenced this pull request Aug 24, 2026
#4408)

Adds `spill_env_e2e_engages_spill_layer` under
`crates/engine/tests/spill_env_e2e.rs`. The test seeds 10 MiB of mixed
pseudo-random content into a `TempDir`, runs `LocalCopyPlan::execute`
with `OC_RSYNC_SPILL_THRESHOLD_BYTES=131072` and `OC_RSYNC_SPILL_DIR`
pointed at a scratch tempdir, then asserts at least one `.tmp` file
landed in the spill directory.

Marked `#[ignore]` until env-var wiring (STN-8 parse, STN-9/STN-10
engine plumbing) lands. The file compiles, the inline `EnvGuard`
serialises env mutation via a per-process `Mutex`, and an inline
xorshift PRNG keeps the corpus deterministic without adding `rand`
as a dev-dependency. Gated on `cfg(unix)` because env-var semantics
differ on Windows.

Closes #2348.
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.

1 participant