Skip to content

feat(match): zsync-inspired matched-block pruning bitmap - #3748

Merged
oferchen merged 2 commits into
masterfrom
feat/zsync-prune-matched-blocks
May 6, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/zsync-prune-matched-blocks

Conversation

@oferchen

@oferchen oferchen commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • New MatchedBlocks bitmap (one bit per basis block_idx) wired into the delta generator so already-emitted Copy targets are skipped on subsequent probes.
  • Adds DeltaSignatureIndex::find_match_bytes_filtered and find_match_slices_filtered; existing find_match_* keep their public API as thin wrappers.
  • Pruning trigger lives in DeltaGenerator::generate post-Copy push, equivalent to zsync librcksum/rsum.c:109-119 write_blocks.
  • Duplicate-content siblings are tracked independently by block_idx, mirroring zsync's per-block hash_entry model. The want_i hint deliberately bypasses the bitmap.
  • Property tests + hand-rolled regressions pin: pruning never reduces Copy-token bytes (in the unique-positions domain), apply round-trip is preserved, and surplus-source occurrences fall through to literal emission cleanly.

Design: docs/design/zsync-prune.md. Closes #2069 (impl) and #2070 (proptest). Composes with #2059 BitHash and the in-flight seq-match work; rebase expected on either landing first.

Test plan

  • cargo nextest run -p matching --all-features -E 'test(matched_blocks)'
  • cargo nextest run -p matching --all-features -E 'test(prune_)'
  • Workspace fmt + clippy (CI)
  • Full nextest suite (CI)
  • Golden byte tests in crates/protocol/tests/golden/ (CI) - must stay byte-identical
  • Interop matrix (tools/ci/run_interop.sh) - no new known_failures entries

@github-actions github-actions Bot added the enhancement New feature or request label May 6, 2026
Introduce MatchedBlocks, a per-generator-session bitmap that records
which basis blocks have already been emitted as DeltaToken::Copy. The
delta generator threads the bitmap into find_match_slices_filtered so
that already-matched basis blocks are skipped before the strong-checksum
verify, mirroring zsync librcksum's matched-block hash removal in
hash.c:111-128 (remove_block_from_hash) triggered at write_blocks
(rsum.c:109-119).

Bits are keyed by basis block_idx, not by (rsum, strong) tuple. Two
blocks with identical content live at distinct block_idx slots, so
marking one leaves the other findable. Pruning only changes which
sibling block_idx is named in a Copy token when duplicate content
exists; the receiver applies the same bytes either way, so the wire
output stays equivalent (golden byte tests unchanged).

The want_i adjacent-match hint deliberately bypasses the bitmap: the
hint targets the just-matched index plus one, which the bitmap leaves
unset by construction.

Property tests pin two contracts from docs/design/zsync-prune.md:

  prune_does_not_reduce_matched_bytes:
    For sources built from a permutation of unique basis-block
    positions, total Copy-token bytes under prune-on are >= prune-off.
  prune_preserves_apply_round_trip:
    apply_delta(basis, generate(basis, source, prune)) == source for
    both prune-on and prune-off.

Hand-rolled regressions also cover three identical basis blocks and
the surplus-source-occurrences case where prune-on correctly falls
through to literal emission once every basis sibling is consumed.

Closes #2069
Closes #2070
@oferchen
oferchen force-pushed the feat/zsync-prune-matched-blocks branch from 38e6c35 to 499e1ad Compare May 6, 2026 08:15
@oferchen
oferchen merged commit aa7eb8a into master May 6, 2026
39 checks passed
@oferchen
oferchen deleted the feat/zsync-prune-matched-blocks branch May 6, 2026 18:55
oferchen added a commit that referenced this pull request May 14, 2026
Introduces CHANGELOG.md and records the four zsync-inspired internal
optimizations to the receiver block-match path: bithash prefilter
(#3737), sequential-match extension (#3751), matched-block pruning
(#3748), and compact-key layout (#3994). All four are wire-compatible
refactors of the in-memory match index; golden-byte fixtures and
interop against upstream rsync 3.0.9 / 3.1.3 / 3.4.1 are unchanged.

Closes #2087.
oferchen added a commit that referenced this pull request May 18, 2026
* feat(match): add zsync-inspired matched-block pruning bitmap

Introduce MatchedBlocks, a per-generator-session bitmap that records
which basis blocks have already been emitted as DeltaToken::Copy. The
delta generator threads the bitmap into find_match_slices_filtered so
that already-matched basis blocks are skipped before the strong-checksum
verify, mirroring zsync librcksum's matched-block hash removal in
hash.c:111-128 (remove_block_from_hash) triggered at write_blocks
(rsum.c:109-119).

Bits are keyed by basis block_idx, not by (rsum, strong) tuple. Two
blocks with identical content live at distinct block_idx slots, so
marking one leaves the other findable. Pruning only changes which
sibling block_idx is named in a Copy token when duplicate content
exists; the receiver applies the same bytes either way, so the wire
output stays equivalent (golden byte tests unchanged).

The want_i adjacent-match hint deliberately bypasses the bitmap: the
hint targets the just-matched index plus one, which the bitmap leaves
unset by construction.

Property tests pin two contracts from docs/design/zsync-prune.md:

  prune_does_not_reduce_matched_bytes:
    For sources built from a permutation of unique basis-block
    positions, total Copy-token bytes under prune-on are >= prune-off.
  prune_preserves_apply_round_trip:
    apply_delta(basis, generate(basis, source, prune)) == source for
    both prune-on and prune-off.

Hand-rolled regressions also cover three identical basis blocks and
the surplus-source-occurrences case where prune-on correctly falls
through to literal emission once every basis sibling is consumed.

Closes #2069
Closes #2070

* fix(match): use slice::fill in matched_blocks property test
oferchen added a commit that referenced this pull request May 18, 2026
Introduces CHANGELOG.md and records the four zsync-inspired internal
optimizations to the receiver block-match path: bithash prefilter
(#3737), sequential-match extension (#3751), matched-block pruning
(#3748), and compact-key layout (#3994). All four are wire-compatible
refactors of the in-memory match index; golden-byte fixtures and
interop against upstream rsync 3.0.9 / 3.1.3 / 3.4.1 are unchanged.

Closes #2087.
oferchen added a commit that referenced this pull request Aug 24, 2026
Introduces CHANGELOG.md and records the four zsync-inspired internal
optimizations to the receiver block-match path: bithash prefilter
(#3737), sequential-match extension (#3751), matched-block pruning
(#3748), and compact-key layout (#3994). All four are wire-compatible
refactors of the in-memory match index; golden-byte fixtures and
interop against upstream rsync 3.0.9 / 3.1.3 / 3.4.1 are unchanged.

Closes #2087.
oferchen added a commit that referenced this pull request Aug 24, 2026
* feat(match): add zsync-inspired matched-block pruning bitmap

Introduce MatchedBlocks, a per-generator-session bitmap that records
which basis blocks have already been emitted as DeltaToken::Copy. The
delta generator threads the bitmap into find_match_slices_filtered so
that already-matched basis blocks are skipped before the strong-checksum
verify, mirroring zsync librcksum's matched-block hash removal in
hash.c:111-128 (remove_block_from_hash) triggered at write_blocks
(rsum.c:109-119).

Bits are keyed by basis block_idx, not by (rsum, strong) tuple. Two
blocks with identical content live at distinct block_idx slots, so
marking one leaves the other findable. Pruning only changes which
sibling block_idx is named in a Copy token when duplicate content
exists; the receiver applies the same bytes either way, so the wire
output stays equivalent (golden byte tests unchanged).

The want_i adjacent-match hint deliberately bypasses the bitmap: the
hint targets the just-matched index plus one, which the bitmap leaves
unset by construction.

Property tests pin two contracts from docs/design/zsync-prune.md:

  prune_does_not_reduce_matched_bytes:
    For sources built from a permutation of unique basis-block
    positions, total Copy-token bytes under prune-on are >= prune-off.
  prune_preserves_apply_round_trip:
    apply_delta(basis, generate(basis, source, prune)) == source for
    both prune-on and prune-off.

Hand-rolled regressions also cover three identical basis blocks and
the surplus-source-occurrences case where prune-on correctly falls
through to literal emission once every basis sibling is consumed.

Closes #2069
Closes #2070

* fix(match): use slice::fill in matched_blocks property test
oferchen added a commit that referenced this pull request Aug 24, 2026
Introduces CHANGELOG.md and records the four zsync-inspired internal
optimizations to the receiver block-match path: bithash prefilter
(#3737), sequential-match extension (#3751), matched-block pruning
(#3748), and compact-key layout (#3994). All four are wire-compatible
refactors of the in-memory match index; golden-byte fixtures and
interop against upstream rsync 3.0.9 / 3.1.3 / 3.4.1 are unchanged.

Closes #2087.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant