Skip to content

perf: decoupled receiver + upstream architectural patterns - #2338

Merged
oferchen merged 6 commits into
masterfrom
perf/decoupled-receiver
Feb 18, 2026
Merged

oferchen merged 6 commits into
masterfrom
perf/decoupled-receiver

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Decoupled receiver — overlap network reads with disk writes using a pipelined architecture
  • Buffer recycling — two-way channel reuses Vec allocations between network and disk threads
  • File pre-allocation — set_len() for direct-write files ≥64KB, reducing FS extent allocation
  • Reusable 256KB write buffer — single ReusableBufWriter across all files (matches upstream wf_writeBuf)
  • Sliding window memmove — reuse overlapping bytes on forward slide in BufferedMap::load_window (mirrors upstream map_ptr() fileio.c:268-279)
  • UTF-8 fast path — String::from_utf8 with lossy fallback instead of unconditional from_utf8_lossy in flist and metadata hot paths
  • Hash table reuse — DeltaSignatureIndex::rebuild() for FxHashMap reuse across files

Benchmark Results

Wall time (hyperfine, 5 runs):

  • upstream rsync 3.4.1: 876ms
  • oc-rsync HEAD: 741ms
  • 1.18x faster than upstream

Callgrind (instruction count):

  • HEAD: 538M instructions
  • UTF-8 path: 4.36M → 4.00M (-356K)

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -D warnings
  • cargo nextest run --workspace --all-features (21,724 tests pass)
  • Callgrind profiling in container
  • Hyperfine wall-time benchmark vs upstream

Implement a producer-consumer architecture that separates network I/O
from disk I/O onto separate threads, mirroring upstream rsync's fork()
model using Rust threads + bounded channels.

Architecture:
- Network thread: reads delta tokens, resolves block refs, verifies
  checksums, streams chunks through sync_channel(32)
- Disk thread: receives Begin/Chunk/Commit messages, opens files,
  writes data, flushes/renames atomically
- PipelinedReceiver mediator coordinates lifecycle and error propagation
- Drop guard ensures clean shutdown even on panic

New files:
- pipeline/messages.rs: FileMessage, BeginMessage, CommitResult types
- disk_commit.rs: spawn_disk_thread(), DiskCommitConfig
- pipeline/receiver.rs: PipelinedReceiver mediator

Removed:
- pipeline/overlapped.rs: superseded by streaming channel architecture

Benchmark (10K files, 401MB, loopback daemon, aarch64):
- HEAD: 771ms (1.00x baseline)
- v0.5.7: 883ms (1.15x slower)
- upstream rsync 3.4.1: 891ms (1.16x slower)
Mirror upstream rsync's memory management patterns to reduce allocator
overhead in the decoupled receiver's disk commit thread.

- Buffer recycling: disk thread returns used Vec<u8> buffers through a
  return channel; network thread reuses them via try_recv() before
  allocating, matching upstream's static buffer in simple_recv_token
  (token.c:284)

- File pre-allocation: call file.set_len(target_size) for direct-write
  files >= 64KB, mirroring upstream's do_fallocate (receiver.c:254-258)

- Reusable 256KB write buffer: ReusableBufWriter borrows a thread-local
  Vec allocated once in disk_thread_main, eliminating per-file BufWriter
  alloc/free. Matches upstream's static wf_writeBuf (fileio.c:161)

- DiskThreadHandle struct replaces complex tuple return from
  spawn_disk_thread (clippy type_complexity)

Callgrind: eliminates ~4M allocator instructions (mi_find_page,
_mi_page_free_collect, mi_heap_malloc_zero_aligned_at_generic,
_mi_malloc_generic all removed from hot path).

Wall time: 1.17x faster than upstream rsync 3.4.1 (768ms vs 895ms
on 10K files / 508MB via rsync daemon).
@oferchen
oferchen merged commit 99fb3a1 into master Feb 18, 2026
30 checks passed
@oferchen
oferchen deleted the perf/decoupled-receiver branch February 18, 2026 11:46
oferchen added a commit that referenced this pull request May 1, 2026
* perf: decoupled receiver — overlap network reads with disk writes

Implement a producer-consumer architecture that separates network I/O
from disk I/O onto separate threads, mirroring upstream rsync's fork()
model using Rust threads + bounded channels.

Architecture:
- Network thread: reads delta tokens, resolves block refs, verifies
  checksums, streams chunks through sync_channel(32)
- Disk thread: receives Begin/Chunk/Commit messages, opens files,
  writes data, flushes/renames atomically
- PipelinedReceiver mediator coordinates lifecycle and error propagation
- Drop guard ensures clean shutdown even on panic

New files:
- pipeline/messages.rs: FileMessage, BeginMessage, CommitResult types
- disk_commit.rs: spawn_disk_thread(), DiskCommitConfig
- pipeline/receiver.rs: PipelinedReceiver mediator

Removed:
- pipeline/overlapped.rs: superseded by streaming channel architecture

Benchmark (10K files, 401MB, loopback daemon, aarch64):
- HEAD: 771ms (1.00x baseline)
- v0.5.7: 883ms (1.15x slower)
- upstream rsync 3.4.1: 891ms (1.16x slower)

* perf: buffer recycling, pre-allocation, and reusable write buffer

Mirror upstream rsync's memory management patterns to reduce allocator
overhead in the decoupled receiver's disk commit thread.

- Buffer recycling: disk thread returns used Vec<u8> buffers through a
  return channel; network thread reuses them via try_recv() before
  allocating, matching upstream's static buffer in simple_recv_token
  (token.c:284)

- File pre-allocation: call file.set_len(target_size) for direct-write
  files >= 64KB, mirroring upstream's do_fallocate (receiver.c:254-258)

- Reusable 256KB write buffer: ReusableBufWriter borrows a thread-local
  Vec allocated once in disk_thread_main, eliminating per-file BufWriter
  alloc/free. Matches upstream's static wf_writeBuf (fileio.c:161)

- DiskThreadHandle struct replaces complex tuple return from
  spawn_disk_thread (clippy type_complexity)

Callgrind: eliminates ~4M allocator instructions (mi_find_page,
_mi_page_free_collect, mi_heap_malloc_zero_aligned_at_generic,
_mi_malloc_generic all removed from hot path).

Wall time: 1.17x faster than upstream rsync 3.4.1 (768ms vs 895ms
on 10K files / 508MB via rsync daemon).

* perf: sliding window memmove — reuse overlapping bytes on forward slide

* perf: avoid UTF-8 lossy conversion in file list hot path

* perf: add DeltaSignatureIndex::rebuild for hash table reuse across files

* perf: avoid UTF-8 lossy conversion in owner/group name mapping
oferchen added a commit that referenced this pull request May 5, 2026
* perf: decoupled receiver — overlap network reads with disk writes

Implement a producer-consumer architecture that separates network I/O
from disk I/O onto separate threads, mirroring upstream rsync's fork()
model using Rust threads + bounded channels.

Architecture:
- Network thread: reads delta tokens, resolves block refs, verifies
  checksums, streams chunks through sync_channel(32)
- Disk thread: receives Begin/Chunk/Commit messages, opens files,
  writes data, flushes/renames atomically
- PipelinedReceiver mediator coordinates lifecycle and error propagation
- Drop guard ensures clean shutdown even on panic

New files:
- pipeline/messages.rs: FileMessage, BeginMessage, CommitResult types
- disk_commit.rs: spawn_disk_thread(), DiskCommitConfig
- pipeline/receiver.rs: PipelinedReceiver mediator

Removed:
- pipeline/overlapped.rs: superseded by streaming channel architecture

Benchmark (10K files, 401MB, loopback daemon, aarch64):
- HEAD: 771ms (1.00x baseline)
- v0.5.7: 883ms (1.15x slower)
- upstream rsync 3.4.1: 891ms (1.16x slower)

* perf: buffer recycling, pre-allocation, and reusable write buffer

Mirror upstream rsync's memory management patterns to reduce allocator
overhead in the decoupled receiver's disk commit thread.

- Buffer recycling: disk thread returns used Vec<u8> buffers through a
  return channel; network thread reuses them via try_recv() before
  allocating, matching upstream's static buffer in simple_recv_token
  (token.c:284)

- File pre-allocation: call file.set_len(target_size) for direct-write
  files >= 64KB, mirroring upstream's do_fallocate (receiver.c:254-258)

- Reusable 256KB write buffer: ReusableBufWriter borrows a thread-local
  Vec allocated once in disk_thread_main, eliminating per-file BufWriter
  alloc/free. Matches upstream's static wf_writeBuf (fileio.c:161)

- DiskThreadHandle struct replaces complex tuple return from
  spawn_disk_thread (clippy type_complexity)

Callgrind: eliminates ~4M allocator instructions (mi_find_page,
_mi_page_free_collect, mi_heap_malloc_zero_aligned_at_generic,
_mi_malloc_generic all removed from hot path).

Wall time: 1.17x faster than upstream rsync 3.4.1 (768ms vs 895ms
on 10K files / 508MB via rsync daemon).

* perf: sliding window memmove — reuse overlapping bytes on forward slide

* perf: avoid UTF-8 lossy conversion in file list hot path

* perf: add DeltaSignatureIndex::rebuild for hash table reuse across files

* perf: avoid UTF-8 lossy conversion in owner/group name mapping
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