Repository navigation
perf: buffer recycling, pre-allocation, and reusable write buffer - #2337
Merged
Merged
Conversation
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
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).
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).
3 tasks done
oferchen
added a commit
that referenced
this pull request
May 18, 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.
Summary
Vec<u8>buffers through a return channel; network thread reuses them viatry_recv()before allocating new ones, matching upstream rsync's static buffer insimple_recv_token(token.c:284)file.set_len(target_size)for direct-write files >= 64KB, mirroring upstream'sdo_fallocate(receiver.c:254-258)ReusableBufWriterborrows a thread-local Vec allocated once indisk_thread_main, eliminating per-file BufWriter alloc/free — matches upstream's staticwf_writeBuf(fileio.c:161)DiskThreadHandlestruct replaces complex tuple return fromspawn_disk_threadBenchmark Results (10K files, 508MB, rsync daemon)
Callgrind: eliminates ~4M allocator instructions (
mi_find_page,_mi_page_free_collect,mi_heap_malloc_zero_aligned_at_generic,_mi_malloc_genericall removed from hot path).Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscargo nextest run --workspace --all-features(21,722 tests pass)