Repository navigation
perf: cut sender seeks and receiver signature allocations - #8210
Merged
Merged
Conversation
…ctor Eliminate intermediate staging allocations, payload clones, and per-item heap churn across the parallel execution and reorder pipeline: - engine::concurrent_delta::reorder: add ReorderBuffer::try_insert() returning Err(item) on capacity overflow so run_bare_loop moves items across drain retries and force_insert without cloning DeltaResult. - engine::concurrent_delta::parallel_apply: compact VerifiedChunk from 184 B to 32 B (dropping the 68 B ChecksumDigest inside the worker), change FileSlot::reorder from ReorderBuffer<DeltaChunk> (112 B/slot) to ReorderBuffer<Box<[u8]>> (16 B fat pointer per slot), and stream next_in_order() directly to the writer in FileSlot::ingest without collecting into an intermediate Vec. - transfer::reorder_buffer: replace BTreeMap<u64, T> and Vec<T> returns in BoundedReorderBuffer<T> with a flat circular ring Vec<Option<T>> and stack-inline DrainedItems<T> (Empty | Single | Batch) for zero heap allocations on in-order and passthrough items. - matching::generator: add scan_stripe_runs (emit_literals = false) so parallel stripe workers emit only 24 B CopyRun descriptors without allocating per-worker literal buffers, and slice gap literals directly from source in merge_copy_runs in a single pass. - signature: replace per-block Vec<Vec<u8>> and per-batch Vec<&[u8]> / Vec<RollingDigest> allocations in sequential and parallel signature generation with a single contiguous read buffer and stack arrays; add FileSignature::release_blocks() and invoke it in transfer_ops::request immediately after wire serialization. - transfer::receiver & writer: lease a pooled BufferGuard in basis.rs for small basis files and release it inside the rayon worker before entering the reorder stage; use a 68 B stack buffer in wire.rs; use IoSlice write_vectored in MultiplexBuffer for oversized frames.
- Wire source_mmap into write_delta_with_inline_checksum so matched blocks read directly from memory rather than re-opening and seeking - Add DeltaToken::LiteralSlice and lifetime-parameterized DeltaScript to borrow literal bytes without heap allocation - Use WireOp to stream literals and copy ops to wire format without intermediate vector allocations - Replace Vec<u8> in DeltaChunk with Box<[u8]> to eliminate capacity reallocations in the parallel delta applier - Fix test fixture permissions to guarantee umask independence across platforms
oferchen
force-pushed
the
perf/zero-alloc-reorder-buffer
branch
from
October 18, 2026 14:46
0df1321 to
4b11fd0
Compare
oferchen
marked this pull request as draft
October 18, 2026 14:49
… pipeline window - crates/core: eliminate CorkedTcpWriter on daemon connections to match upstream rsync TCP semantics, removing 40ms delayed-ACK stalls on sub-MSS writes - crates/transfer: set DEFAULT_PIPELINE_WINDOW to 32, matching upstream rsync's IOBUF_SIZE (32 KiB) to prevent socket write buffer saturation - crates/transfer: propagate is_new (ITEM_IS_NEW) through the transfer pipeline, skipping basis file lookup and statx(ENOENT) checks on new destination paths matching upstream generator.c:2378 - crates/engine: switch CleanupManager to lock-free DashSet and box LocalCopyMetadata - crates/metadata: skip redundant chown calls when destination ownership matches
- crates/cli/src/frontend/tests/common.rs: acquire RUN_LOCK in run_with_args to serialize top-level reentrant cli::run invocations across test worker threads - crates/cli/src/frontend/tests/parse_max_alloc.rs: enforce ENV_LOCK guards around environment variable mutations and test runs - crates/cli/src/frontend/tests/clap.rs: route test invocation through run_with_args - src/bin/client.rs: add TEST_LOCK to serialize client test runs
Restores CorkedTcpWriter, the ownership chown decision, the 64-entry pipeline window and the pre-existing basis checks, and removes the cleanup DashSet and CLI test locks. These change behaviour outside the zero-copy delta and reorder-buffer scope and need their own measured PRs.
Drops the LiteralSlice variant and the two literal_data helpers, restores master behaviour for the multiplex oversized-frame write, and keeps the basis reader capacity clamp as the only small-basis change.
The ring was pre-sized to min(window, 2^20) while admission still allowed any offset below the window, so a release build wrapped a deep gap onto an occupied slot. Growing by doubling from 16 slots also keeps memory at the observed reorder depth instead of the configured window. The sender emit pass now feeds matched blocks through one CopySource helper.
BoundedReorderBuffer, the engine ReorderBuffer and the parallel-apply consumer have no production caller, so their rewrite can neither carry nor be gated by a transfer-level measurement. Also refuse an oversized strong sum width in write_signature_blocks instead of silently clamping it.
With --parallel-delta-scan the emit pass borrowed literals and matched blocks from the source map while it could block on the network, so a truncation of the source mid-send killed the sender with SIGBUS (exit 135) where master reports a read error (exit 23). The script is now detached with into_owned() and the map dropped before emitting; matched blocks are re-read through read(2) as on master.
The parallel merge frames gap literals with push_split_literal_slice; resegment_literals no longer exists, so its doc link was broken.
CopySource is generic over its reader so a counting Seek can show that adjacent matched blocks share one seek, and that a literal gap or a short read forces a re-seek. Always seeking still yields correct bytes, so only a seek count catches that regression.
The sequential generator hashes blocks from one strided batch buffer and the parallel path delegates to it, so parity between them cannot catch a slicing slip. Compare each block of a three-batch file with a short final block against rolling and strong digests computed over its own bytes.
release_blocks must free the block list while keeping the layout and total bytes. The basis read buffer is now a named function sized to the file within a floor and the MAX_MAP_SIZE window, with its bounds tested.
oferchen
marked this pull request as ready for review
October 20, 2026 09:47
14 of 15 tasks
oferchen
enabled auto-merge (squash)
October 20, 2026 11:43
24 of 27 tasks
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
CopySourcereuses the file position and itsBufReader, so a daemon push drops from 80,020 to 2,264lseekcalls and from 86,303 to 42,803 reads on the sender. Wall time drops 12-15% on daemon transfers.Vecper block. Each block is released once it is on the wire, and the basis reader buffer is sized to the file. Pull receiver allocations fall 44% (177,818 to 98,935) and bytes 56% (1,361.5 MB to 600.3 MB).CHUNK_SIZEsplitting, compressor dictionary bytes and checksum order are identical to master; the golden and parity tests below pin this.Details
Sender.
DeltaTokenhas oneLiteral(Cow<'a, [u8]>)variant. Literals are borrowed on the parallel scan and owned on the sequential scan, andWireOpborrows them from the script instead of taking them by value.--parallel-delta-scanthe script is detached withDeltaScript::into_owned()before the map is dropped, so each literal is copied once. Master copied twice, inmerge_copy_runsand in the oldresegment_literals.read(2)(CopySource), as on master. There is no mmap-backed checksum.Receiver.
generate_file_signaturefills one contiguous batch buffer, and the parallel entry point delegates to the windowed generator. Both produce output identical to master, including the short final block and the trailing-data and EOF checks.FileSignature::release_blocksfrees the block list once the request is written; delta reconstruction only readslayout().basis_reader_capacity(size): the file size, clamped between 8 KiB andMAX_MAP_SIZE.Fixed during review:
SIGBUS under
--parallel-delta-scan. The emit pass borrowed from the source mmap while it could block on the network, so truncating the source mid-send killed the sender (exit 135). The map is now dropped after the scan and literals are owned. The truncate-during-send probe, a 256 MiB push under--bwlimit=16mwithtruncate -s 1Mafter 3 s:--parallel-delta-scanOversized strong-sum width.
write_signature_blockssilently clampeds2lengthto 64. It now refuses any width aboveMAX_STRONG_SUM_LENwithInvalidInput, as upstream does (io.c:2279), because a truncated sum would desync the peer.Multiplex frames. Oversized frames are back to a single staged
write_all(io.c:1088,send_msg()).Citations. The upstream citations deleted by the rewrite are restored:
fileio.c:330-336andmatch.c:197,372-373.Removed from the original PR. None of these carries a measurable share of the gain; see the attribution table.
ReorderBuffer, parallel-apply andchunk_adapterchangesCorkedTcpWriterremovalownership.rsIOBUF_SIZEis_newbasis skipcleanup.rsDashSet, CLI test locks, keep-dirlinks change, fixture permission tweaksDeltaOp::literal_data,DeltaToken::literal_dataMeasurements.
strace -f -ctotals, client + daemon.-z--parallel-delta-scanThe
-zdaemon total swings withfutexwake-ups alone. Three repeats per binary gave 105,068 / 105,507 / 136,324 on master and 103,168 / 103,340 / 149,119 on this head. The I/O syscalls are equal or lower (read8,106 to 7,594), and the client side is stable at about 177.5K on master against 56.1K on this head.Attribution: the original PR head and this head match within noise on every cell. The exception is the parallel scan, where this head re-reads matched blocks through
read(2)for SIGBUS safety (+32.8K reads) with wall time within noise.-z--parallel-delta-scanAllocations were measured with DHAT on system-allocator builds. The pull receiver drops from 177,818 to 98,935 allocations and from 1,361.5 MB to 600.3 MB. The push sender is unchanged at 193,359, so the sender changes save syscalls, not allocations. Peak RSS is within 3% of master in every cell.
A candidate that folded the whole-file checksum into the scan cut sender syscalls by 77% but slowed the literal-heavy push by 20-30% in 7 of 7 runs, so it is not included.
Test plan
cargo fmt --all -- --checkandpython3 tools/ci/check_rustfmt_all.py.cargo clippy -p matching -p transfer -p signature --all-targets --all-features --no-deps -- -D warnings.RUSTDOCFLAGS="-D rustdoc::broken_intra_doc_links" cargo doc -p matching --no-deps --document-private-items(it fails on the previous head's link toresegment_literals).cargo nextest run -p matching -p signature --all-features: 607 passed.cargo nextest run -p transfer --all-features -E 'test(/generator::delta|receiver::basis|receiver::wire|transfer_ops|generator::tests|receiver::tests::delta_apply/)': 379 passed.cargo nextest run -p protocol --all-features -E 'test(/golden/)': 421 passed.cargo nextest run -p engine --all-features -E 'binary(delta_reconstruction_tests) | binary(single_byte_transfer_tests)': 55 passed.cargo run --locked -p xtask -- no-placeholders.-z: every case exits 0 and is byte-identical on this head and on master. The cases are an empty file, a single byte, exactly one block, a short final block, all-literal, all-match,--block-size=131072,--inplace, and batch write plus--read-batch.Each behaviour change is pinned by a test. Each new test was mutation-checked and goes red under its mutation:
generator::delta::tests::copy_source_skips_seek_for_adjacent_blocks_and_reseeks_otherwiseround_trip::every_block_matches_direct_digests_across_batch_boundaries(36 blocks over 3 batches, 123-byte final block, MD4 and XXH3-128)release_blocksfile::tests::release_blocks_drops_blocks_and_keeps_layoutclear()instead of freeing: capacity assertion failsreceiver::basis::tests::basis_reader_capacity_tracks_the_file_within_boundsMAX_MAP_SIZE: failss2lengthrefusaloversized_strong_sum_length_is_refusedinto_owned_detaches_borrowed_literalsliteral_bytesininto_owned: failsLiteral(Cow)wire identityparallel_delta_wire_parity,zsync_wire_parityRemoving
into_owned()also fails to compile, because the map is moved into the scan arm and dropped there. The truncate-during-send exit 23 is covered by the probe table above rather than by a test, because a test would depend on timing to land the truncation mid-send.Coordination
Vecon the push sender;Conventional commit prefix
perf:- performance improvementPre-merge checklist
cargo fmt --allrun locally.CHANGELOG.mdupdated if user-visible.SECURITY.mdupdated if security-relevant.