Repository navigation
perf: reduce checksum and memcpy overhead in receiver pipeline - #2340
Merged
Merged
Conversation
Add a DIRECT_WRITE_THRESHOLD (8 KB) to ReusableBufWriter. Chunks at or above this size skip the intermediate buffer copy and write directly to the file descriptor. This eliminates one memcpy from the hot path for typical rsync literal tokens (32 KB+) while preserving syscall batching for tiny delta tokens. The 256 KB write buffer (matching upstream's wf_writeBuf) is still used for small chunks to amortize syscall overhead.
…read Defer per-file integrity checksum (XXH3/MD5/etc) from the network thread to the disk commit thread, overlapping hashing with disk I/O. The network thread now focuses solely on reading the wire protocol. Architecture: - BeginMessage carries Option<ChecksumVerifier> to the disk thread - Disk thread calls verifier.update() on each chunk before writing - CommitResult returns ComputedChecksum for deferred verification - PipelinedReceiver maintains a FIFO queue of expected checksums and verifies each CommitResult in drain_ready/drain_all_results Benchmark: 1.50x faster than upstream rsync (604ms vs 909ms, 10K files, 422MB, data integrity verified via md5sum comparison).
Remove the 64KB BufReader that wrapped stdin before MultiplexReader. MultiplexReader already provides its own 64KB buffer (matching upstream rsync's iobuf_in), making the outer BufReader redundant. Data now flows directly from the socket to MultiplexReader's buffer, eliminating one memcpy layer on every byte received. This mirrors the write side, which already documents: "No BufWriter: MultiplexWriter provides all buffering."
In the streaming token loop, the fallback path for tokens spanning multiplex frame boundaries previously copied data through TokenBuffer before copying again into the channel Vec. Now reads directly into the Vec, eliminating one memcpy for cross-frame tokens. Also removes the now-unused token_buffer parameter from process_file_response_streaming and its callers.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
…erhead perf: reduce checksum and memcpy overhead in receiver pipeline
oferchen
added a commit
that referenced
this pull request
May 5, 2026
…erhead perf: reduce checksum and memcpy overhead in receiver pipeline
1 of 3 tasks
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`. # Conflicts: # crates/engine/src/concurrent_delta/consumer.rs # crates/engine/src/concurrent_delta/spill/mod.rs # crates/engine/src/concurrent_delta/spill/policy.rs
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) (#4421) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`. # Conflicts: # crates/engine/src/concurrent_delta/consumer.rs # crates/engine/src/concurrent_delta/spill/mod.rs # crates/engine/src/concurrent_delta/spill/policy.rs
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) (#4421) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`. # Conflicts: # crates/engine/src/concurrent_delta/consumer.rs # crates/engine/src/concurrent_delta/spill/mod.rs # crates/engine/src/concurrent_delta/spill/policy.rs
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…_bytes (STN-6 #2340) (#4421) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`. # Conflicts: # crates/engine/src/concurrent_delta/consumer.rs # crates/engine/src/concurrent_delta/spill/mod.rs # crates/engine/src/concurrent_delta/spill/policy.rs
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…_bytes (STN-6 #2340) (#4421) Adds an opt-in process-RSS threshold that forces the concurrent-delta reorder buffer to spill independently of the byte budget. When set, `SpillableReorderBuffer` consults a cached `/proc/self/statm` reading (refreshed every 100 ms) before checking `threshold_bytes`, so transient RSS spikes drain at least one item to disk per insert. Default behaviour is preserved: the new field defaults to `None`, all existing tests pass without modification. Platform handling: - Linux reads `/proc/self/statm` and multiplies the resident-pages field by the safe `rustix::param::page_size()` shim. - macOS ships an `Ok(0)` stub so the knob is a no-op until a follow-up wires `mach_task_basic_info` (tracked separately). - Other platforms (notably Windows) return `Unsupported`; the buffer silently falls back to the byte-budget path. The RSS module sits under `crates/engine/src/concurrent_delta/spill/rss.rs` with no unsafe code in the engine crate (rustix already covers the page size lookup) and three unit tests cover the default, threshold-trip, and unsupported-platform paths. `SpillPolicy.memory_pressure_bytes` is the last field in the struct so STN-3/4/5 rebases stay mechanical with `..Default::default()`. # Conflicts: # crates/engine/src/concurrent_delta/consumer.rs # crates/engine/src/concurrent_delta/spill/mod.rs # crates/engine/src/concurrent_delta/spill/policy.rs
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
Architecture
BeginMessagenow carries anOption<ChecksumVerifier>to the disk thread. The disk thread hashes each chunk as it writes and returns aComputedChecksuminCommitResult.PipelinedReceivermaintains a FIFO queue of expected checksums and verifies them when draining results.Benchmark
10,000 files (422 MB), daemon loopback,
--no-whole-filedisabled:Data integrity verified via md5sum comparison of all 10,000 files.
Test plan
cargo clippy --workspace --all-targets --all-features --no-deps -D warningscargo nextest run --workspace --all-features(21,724 tests pass)