Repository navigation
feat(match): zsync-inspired sequential-match lookahead (ZSO-2) - #4624
Merged
Merged
Conversation
Record the source-order successor of every indexed basis block in a new `next_match: Vec<u32>` parallel array on `DeltaSignatureIndex`, populated in a single pass during `populate_index` and cleared by `rebuild` so the per-segment INC_RECURSE lifecycle stays leak-free (ZSO-7). Expose two new probe entry points - `try_next_match_bytes` and `try_next_match_slices` - that consult the recorded successor, verify the strong checksum, and skip the tag-table / bithash / compact-lookup probe chain on the common "next block in source order matches the next window" path. Test-only `SeqMatchCounters` (probes / hits / misses) hang off the index behind the existing `bench-internal` cfg gate, carrying zero overhead in release builds. Wire the generator's in-chain probe (the one taken after every confirmed match) onto the new `try_next_match_slices` so the lookahead is driven through the index's link table rather than the prior `match_idx + 1` arithmetic. The start-of-file `Some(0)` seed continues to use the existing `check_block_match_slices` shortcut. Tests in `crates/matching/src/index/seq_match_tests.rs` cover: - the successor chain and out-of-range contract for `next_match`, - hit / miss / tail-block behaviour for the new probes (with counter assertions), - generator wiring (6 sequential blocks => 5 probes / 5 hits / 0 misses; divergent source => >= 1 miss with the full lookup taking over), - per-segment isolation across `rebuild` mirroring the bithash leak test, - a proptest over basis sizes 2..=8 pinning the successor link. Wire-byte parity preserved: protocol golden tests (407 cases) pass.
5 tasks done
oferchen
added a commit
that referenced
this pull request
May 21, 2026
…SO-5) Adds the ZSO-5 (task #2513) regression suite at crates/matching/tests/zsync_wire_parity.rs. For each ZSO-1..4 optimization, constructs a basis + source pair designed to exercise that optimization's code path, runs generate_delta, serialises the DeltaScript through the production wire-format encoder (protocol::wire::write_token_stream), and pins the resulting bytes against (a) determinism across repeated runs and (b) round-trip reconstruction of the source via apply_delta. Active tests: - bithash_optimization_preserves_wire_bytes (ZSO-1, task #2510, shipped in PR #3737) - 16 KiB random basis + disjoint random source so every rolling probe walks the bithash reject path. Asserts all-literal script and deterministic wire bytes. - seq_match_optimization_preserves_wire_bytes (ZSO-2, task #2510, landing on PR #4624) - 84-block basis used as its own source so every adjacent-block hint fires. Asserts single fat Copy token and deterministic wire bytes. Test was authored to remain green on master (extend_run + script-level coalescing already produce the pinned shape) and stays green when PR #4624 swaps the probe path. - all_active_zso_fixtures_are_deterministic - cross-cutting check that signals "matching pipeline became non-deterministic" as a single failure. Stub tests (#[ignore]): - hash_chain_prune_preserves_wire_bytes (ZSO-3, task #2511) - compact_rolling_key_preserves_wire_bytes (ZSO-4, task #2512) The stubs are structured so the only step required when those optimizations land is to drop #[ignore] and swap the placeholder basis/source for the duplicate-heavy / small-basis corpora documented in the test rustdoc. Complements the protocol-layer golden tests at crates/protocol/tests/golden_protocol_v28_mplex_delta_stats.rs which pin the token frame format but do not synthesize ZSO-specific basis fixtures. No production code changes. No new dependencies (uses a small in-test LCG to keep the corpus deterministic). All 321 matching tests pass; 407 protocol golden tests pass.
oferchen
added a commit
that referenced
this pull request
May 21, 2026
…SO-5) (#4627) Adds the ZSO-5 (task #2513) regression suite at crates/matching/tests/zsync_wire_parity.rs. For each ZSO-1..4 optimization, constructs a basis + source pair designed to exercise that optimization's code path, runs generate_delta, serialises the DeltaScript through the production wire-format encoder (protocol::wire::write_token_stream), and pins the resulting bytes against (a) determinism across repeated runs and (b) round-trip reconstruction of the source via apply_delta. Active tests: - bithash_optimization_preserves_wire_bytes (ZSO-1, task #2510, shipped in PR #3737) - 16 KiB random basis + disjoint random source so every rolling probe walks the bithash reject path. Asserts all-literal script and deterministic wire bytes. - seq_match_optimization_preserves_wire_bytes (ZSO-2, task #2510, landing on PR #4624) - 84-block basis used as its own source so every adjacent-block hint fires. Asserts single fat Copy token and deterministic wire bytes. Test was authored to remain green on master (extend_run + script-level coalescing already produce the pinned shape) and stays green when PR #4624 swaps the probe path. - all_active_zso_fixtures_are_deterministic - cross-cutting check that signals "matching pipeline became non-deterministic" as a single failure. Stub tests (#[ignore]): - hash_chain_prune_preserves_wire_bytes (ZSO-3, task #2511) - compact_rolling_key_preserves_wire_bytes (ZSO-4, task #2512) The stubs are structured so the only step required when those optimizations land is to drop #[ignore] and swap the placeholder basis/source for the duplicate-heavy / small-basis corpora documented in the test rustdoc. Complements the protocol-layer golden tests at crates/protocol/tests/golden_protocol_v28_mplex_delta_stats.rs which pin the token frame format but do not synthesize ZSO-specific basis fixtures. No production code changes. No new dependencies (uses a small in-test LCG to keep the corpus deterministic). All 321 matching tests pass; 407 protocol golden tests pass.
5 tasks done
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Record the source-order successor of every indexed basis block in a new `next_match: Vec<u32>` parallel array on `DeltaSignatureIndex`, populated in a single pass during `populate_index` and cleared by `rebuild` so the per-segment INC_RECURSE lifecycle stays leak-free (ZSO-7). Expose two new probe entry points - `try_next_match_bytes` and `try_next_match_slices` - that consult the recorded successor, verify the strong checksum, and skip the tag-table / bithash / compact-lookup probe chain on the common "next block in source order matches the next window" path. Test-only `SeqMatchCounters` (probes / hits / misses) hang off the index behind the existing `bench-internal` cfg gate, carrying zero overhead in release builds. Wire the generator's in-chain probe (the one taken after every confirmed match) onto the new `try_next_match_slices` so the lookahead is driven through the index's link table rather than the prior `match_idx + 1` arithmetic. The start-of-file `Some(0)` seed continues to use the existing `check_block_match_slices` shortcut. Tests in `crates/matching/src/index/seq_match_tests.rs` cover: - the successor chain and out-of-range contract for `next_match`, - hit / miss / tail-block behaviour for the new probes (with counter assertions), - generator wiring (6 sequential blocks => 5 probes / 5 hits / 0 misses; divergent source => >= 1 miss with the full lookup taking over), - per-segment isolation across `rebuild` mirroring the bithash leak test, - a proptest over basis sizes 2..=8 pinning the successor link. Wire-byte parity preserved: protocol golden tests (407 cases) pass.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…SO-5) (#4627) Adds the ZSO-5 (task #2513) regression suite at crates/matching/tests/zsync_wire_parity.rs. For each ZSO-1..4 optimization, constructs a basis + source pair designed to exercise that optimization's code path, runs generate_delta, serialises the DeltaScript through the production wire-format encoder (protocol::wire::write_token_stream), and pins the resulting bytes against (a) determinism across repeated runs and (b) round-trip reconstruction of the source via apply_delta. Active tests: - bithash_optimization_preserves_wire_bytes (ZSO-1, task #2510, shipped in PR #3737) - 16 KiB random basis + disjoint random source so every rolling probe walks the bithash reject path. Asserts all-literal script and deterministic wire bytes. - seq_match_optimization_preserves_wire_bytes (ZSO-2, task #2510, landing on PR #4624) - 84-block basis used as its own source so every adjacent-block hint fires. Asserts single fat Copy token and deterministic wire bytes. Test was authored to remain green on master (extend_run + script-level coalescing already produce the pinned shape) and stays green when PR #4624 swaps the probe path. - all_active_zso_fixtures_are_deterministic - cross-cutting check that signals "matching pipeline became non-deterministic" as a single failure. Stub tests (#[ignore]): - hash_chain_prune_preserves_wire_bytes (ZSO-3, task #2511) - compact_rolling_key_preserves_wire_bytes (ZSO-4, task #2512) The stubs are structured so the only step required when those optimizations land is to drop #[ignore] and swap the placeholder basis/source for the duplicate-heavy / small-basis corpora documented in the test rustdoc. Complements the protocol-layer golden tests at crates/protocol/tests/golden_protocol_v28_mplex_delta_stats.rs which pin the token frame format but do not synthesize ZSO-specific basis fixtures. No production code changes. No new dependencies (uses a small in-test LCG to keep the corpus deterministic). All 321 matching tests pass; 407 protocol golden tests pass.
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
Adds a zsync-style sequential-match lookahead (ZSO-2 / #2510) on
DeltaSignatureIndex. After a confirmed match at basis blockK, the matcher probes a recorded successor link first and only falls back to the rolling-rsum / bithash / compact-lookup chain on miss. The optimization is purely in-memory: no wire bytes change.next_match: Vec<u32>(withu32::MAXsentinel) on eachDeltaSignatureIndex, populated in a single pass duringpopulate_indexand reset byrebuildfor the per-segment INC_RECURSE lifecycle (ZSO-7).try_next_match_bytes/try_next_match_slicesprobe APIs that follow the recorded successor, do a cheap rolling-sum compare, then a strong-checksum verify. Skip the tag-table / bithash / compact-lookup work on hit.SeqMatchCounters(probes/hits/misses) wired behind the existingbench-internalcfg gate so release builds carry zero overhead. Test-only accessorseq_match_counters()lets the regression suite assert the lookahead path is taken.try_next_match_slices; the start-of-fileSome(0)seed continues to use the existingcheck_block_match_slicesshortcut. Thematch_idx + 1arithmetic is replaced byindex.next_match(match_idx)so any future basis re-ordering is honoured automatically.Wire-byte parity
Wire format is unchanged by construction: nothing serialized changes, only the in-memory probe ordering. Verified by running the protocol golden suite both before and after:
Measured behaviour (counter-based)
The regression suite pins concrete probe / hit / miss counts straight from the new counters:
seq_match_hits_consecutive_blocks(6 distinct blocks, source = basis):probes = 5,hits = 5,misses = 0seq_match_falls_back_on_mismatch(3 basis blocks followed byblock_len + 7literal bytes):hits >= 2(both in-run transitions take the lookahead),misses >= 1(the divergence after block 2 forces a fall-through tofind_match_slices_filtered).next_match_is_consistent_with_basis_order(proptest, 2..=8 blocks): every interior block resolves its successor throughtry_next_match_byteswith no misses.Throughput
Existing
seq_match_redundantbench harness (cargo bench -p matching --features bench-internal --bench seq_match_redundant -- --quick) on the post-change tree:log_like(16 MiB, append-only log fixture)tar_like(16 MiB, near-duplicate records)random_control(16 MiB, uncorrelated)A wire-trapped before/after speedup number would need a long-running, controlled benchmark pass on a quiet host; the harness above is the bench infra the design note (
docs/design/zsync-seq-match.md) calls for and is preserved unchanged.Test plan
cargo fmt --all -- --checkcleancargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p matching --all-features- 330 passed, 3 skippedcargo nextest run -p protocol --all-features -E 'test(golden)'- 407 passed (wire-byte parity)cargo bench -p matching --features bench-internal --bench seq_match_redundant -- --quickruns cleanly