Skip to content

perf(match): replace FxHashMap with flat open-addressing CompactLookup (#2072) - #3994

Merged
oferchen merged 3 commits into
masterfrom
perf/zsync-compact-keys-2072
May 13, 2026
Merged

oferchen merged 3 commits into
masterfrom
perf/zsync-compact-keys-2072

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Replace FxHashMap<(u16, u16), Vec<usize>> in DeltaSignatureIndex with CompactLookup, a flat open-addressing hash table using Robin Hood probing
  • Each entry is 8 bytes (4-byte packed rsum key + 4-byte block index), fitting 8 entries per 64-byte cache line - eliminates pointer-chasing through heap-allocated Vec<usize> buckets
  • Remove unused parallel feature and rayon optional dependency from the match crate (parallel candidate verification was only possible with the old Vec-based buckets)

Design

Adapts zsync's librcksum/hash.c flat layout for the delta match index. The probe chain uses the Robin Hood invariant for early termination: iteration stops when encountering an entry whose probe distance is less than the current scan distance, since no matching entry can exist beyond that point.

Load factor is kept below 25% (4x over-allocation) to maintain probe-chain locality. The u32::MAX sentinel key is reserved for empty slots - the probability of a real rsum hitting this value is negligible, and the tag_table + bithash filters would catch it first.

Test plan

  • 7 unit tests in compact_lookup.rs covering insert/find, missing keys, duplicate keys, distinct keys, clear, stress (10K entries), probe distance wrapping, and key packing
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl
  • Existing delta matching tests exercise the full probe chain through CompactLookup

#2072)

Replace the pointer-chasing FxHashMap<(u16, u16), Vec<usize>> in
DeltaSignatureIndex with a flat open-addressing hash table using Robin
Hood probing. Each entry is 8 bytes (packed rsum key + block index),
fitting 8 entries per 64-byte cache line.

This eliminates heap-allocated Vec<usize> buckets and their pointer
indirection, improving cache locality during the block-matching hot
loop. The CompactLookup iterator terminates early using the Robin Hood
invariant (no matching entry can exist beyond a slot whose probe
distance is less than the scan distance).

Also removes the now-unused `parallel` feature and rayon optional
dependency from the match crate, since the parallel candidate
verification path was only possible with the old Vec-based buckets.
@oferchen
oferchen merged commit 58860a8 into master May 13, 2026
40 checks passed
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
oferchen deleted the perf/zsync-compact-keys-2072 branch May 14, 2026 14:58
oferchen added a commit that referenced this pull request May 18, 2026
#2072) (#3994)

* perf(match): replace FxHashMap with flat open-addressing CompactLookup (#2072)

Replace the pointer-chasing FxHashMap<(u16, u16), Vec<usize>> in
DeltaSignatureIndex with a flat open-addressing hash table using Robin
Hood probing. Each entry is 8 bytes (packed rsum key + block index),
fitting 8 entries per 64-byte cache line.

This eliminates heap-allocated Vec<usize> buckets and their pointer
indirection, improving cache locality during the block-matching hot
loop. The CompactLookup iterator terminates early using the Robin Hood
invariant (no matching entry can exist beyond a slot whose probe
distance is less than the scan distance).

Also removes the now-unused `parallel` feature and rayon optional
dependency from the match crate, since the parallel candidate
verification path was only possible with the old Vec-based buckets.

* fix: regenerate Cargo.lock after removing rayon from matching crate

* fix(match): add capacity() method to CompactLookup

Tests reference capacity() to verify allocation reuse across rebuild.
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
#2072) (#3994)

* perf(match): replace FxHashMap with flat open-addressing CompactLookup (#2072)

Replace the pointer-chasing FxHashMap<(u16, u16), Vec<usize>> in
DeltaSignatureIndex with a flat open-addressing hash table using Robin
Hood probing. Each entry is 8 bytes (packed rsum key + block index),
fitting 8 entries per 64-byte cache line.

This eliminates heap-allocated Vec<usize> buckets and their pointer
indirection, improving cache locality during the block-matching hot
loop. The CompactLookup iterator terminates early using the Robin Hood
invariant (no matching entry can exist beyond a slot whose probe
distance is less than the scan distance).

Also removes the now-unused `parallel` feature and rayon optional
dependency from the match crate, since the parallel candidate
verification path was only possible with the old Vec-based buckets.

* fix: regenerate Cargo.lock after removing rayon from matching crate

* fix(match): add capacity() method to CompactLookup

Tests reference capacity() to verify allocation reuse across rebuild.
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
#2072) (#3994)

* perf(match): replace FxHashMap with flat open-addressing CompactLookup (#2072)

Replace the pointer-chasing FxHashMap<(u16, u16), Vec<usize>> in
DeltaSignatureIndex with a flat open-addressing hash table using Robin
Hood probing. Each entry is 8 bytes (packed rsum key + block index),
fitting 8 entries per 64-byte cache line.

This eliminates heap-allocated Vec<usize> buckets and their pointer
indirection, improving cache locality during the block-matching hot
loop. The CompactLookup iterator terminates early using the Robin Hood
invariant (no matching entry can exist beyond a slot whose probe
distance is less than the scan distance).

Also removes the now-unused `parallel` feature and rayon optional
dependency from the match crate, since the parallel candidate
verification path was only possible with the old Vec-based buckets.

* fix: regenerate Cargo.lock after removing rayon from matching crate

* fix(match): add capacity() method to CompactLookup

Tests reference capacity() to verify allocation reuse across rebuild.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant