Skip to content

bench(matching): compact-keys cache behavior across L1/L2/LLC sizes (#2073) - #4188

Merged
oferchen merged 3 commits into
masterfrom
bench/zsync-compact-keys-cache-2073
May 16, 2026
Merged

oferchen merged 3 commits into
masterfrom
bench/zsync-compact-keys-cache-2073

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds crates/matching/benches/compact_keys_cache.rs, a Criterion bench that profiles DeltaSignatureIndex's compact lookup table at index sizes spanning L1 (~32 KiB), L2 (~512 KiB), LLC (~32 MiB), and main memory (~256 MiB), under both sequential and scattered probe access patterns.
  • Gated behind the existing bench-internal feature; the bench is excluded from default builds and never reaches release binaries.
  • Adds three read-only #[cfg(feature = "bench-internal")] accessors on DeltaSignatureIndex - lookup_capacity, lookup_bytes, lookup_probe - so the bench can isolate the open-addressed Robin Hood probe chain from the rest of the match pipeline.

Why

The bench produces the cache-behavior evidence needed to decide whether the packed (rsum_low | bucket_idx) layout proposed in #2072 is worth implementing. Top-of-file documentation captures:

  • How to wrap the bench with perf stat -e cache-misses,cache-references,LLC-loads,LLC-load-misses for hardware counter data on Linux.
  • How to run under valgrind --tool=cachegrind with explicit --LL, --D1, --I1 parameters for a deterministic, host-independent cache simulation. The bench prints the lookup-table footprint in bytes on stderr so the operator can pick --LL sizes that bracket the workload.
  • Favorable / unfavorable thresholds that map measured numbers to a go / defer decision on Fix ignore-times handling for quick checks #2072.

Methodology

  • Forced block length of 64 bytes so basis allocations stay bounded; the largest (ram) tier needs ~512 MiB during index build and is opt-in via MATCHING_BENCH_MAX_ENTRIES.
  • Index built outside the timed section. Basis bytes dropped before benchmarking so the resident set is the lookup table plus pre-computed probe key streams.
  • Deterministic xorshift64* fill keys both the basis bytes and the scattered-probe permutation so runs are reproducible and cachegrind diffs are stable.
  • Two probe streams per tier: sequential walks basis blocks in index order (prefetcher-friendly), scattered walks via an xorshift permutation that defeats prefetching.

Production impact

None. The bench file is gated behind bench-internal, the accessors are gated behind the same feature, and the existing index hot path is untouched.

Test plan

  • CI: fmt + clippy passes.
  • CI: workspace nextest passes (no production code touched, but bench-internal-gated additions get compile-checked via the bench harness).
  • Manual (when hardware is available): cargo bench -p matching --features bench-internal --bench compact_keys_cache on a Linux host with perf to capture the cache-miss numbers for the Fix ignore-times handling for quick checks #2072 decision.
  • Manual: valgrind --tool=cachegrind run with the bench binary to produce host-independent miss counts.

@oferchen
oferchen force-pushed the bench/zsync-compact-keys-cache-2073 branch 2 times, most recently from 185ed9e to 174d81f Compare May 16, 2026 22:08
oferchen added 3 commits May 17, 2026 01:30
…2073)

Adds a Criterion bench that profiles DeltaSignatureIndex's compact
lookup table at index sizes spanning L1 (~32 KiB), L2 (~512 KiB),
LLC (~32 MiB), and main memory (~256 MiB), with sequential and
scattered probe access patterns.

The bench supplies the evidence needed to decide whether a packed
(rsum_low | bucket_idx) layout (#2072) would meaningfully improve
cache behavior over the current 8-byte slot layout. Top-of-file
comments document the perf stat and cachegrind invocations and the
favorable / unfavorable thresholds that should inform the decision.

Production code is unchanged. The bench-internal feature gains three
read-only accessors on DeltaSignatureIndex (lookup_capacity,
lookup_bytes, lookup_probe) so the bench can isolate the open-
addressed probe chain from the surrounding match pipeline.
@oferchen
oferchen force-pushed the bench/zsync-compact-keys-cache-2073 branch from 174d81f to 9329061 Compare May 16, 2026 22:30
@oferchen
oferchen merged commit 9eac1db into master May 16, 2026
14 checks passed
@oferchen
oferchen deleted the bench/zsync-compact-keys-cache-2073 branch May 16, 2026 22:31
oferchen added a commit that referenced this pull request May 18, 2026
…2073) (#4188)

* bench(matching): compact-keys cache behavior across L1/L2/LLC sizes (#2073)

Adds a Criterion bench that profiles DeltaSignatureIndex's compact
lookup table at index sizes spanning L1 (~32 KiB), L2 (~512 KiB),
LLC (~32 MiB), and main memory (~256 MiB), with sequential and
scattered probe access patterns.

The bench supplies the evidence needed to decide whether a packed
(rsum_low | bucket_idx) layout (#2072) would meaningfully improve
cache behavior over the current 8-byte slot layout. Top-of-file
comments document the perf stat and cachegrind invocations and the
favorable / unfavorable thresholds that should inform the decision.

Production code is unchanged. The bench-internal feature gains three
read-only accessors on DeltaSignatureIndex (lookup_capacity,
lookup_bytes, lookup_probe) so the bench can isolate the open-
addressed probe chain from the surrounding match pipeline.

* style(matching): apply rustfmt to compact_keys_cache bench

* style(matching): inline MAX_ENTRIES_ENV in format string
oferchen added a commit that referenced this pull request May 18, 2026
…2073) (#4188)

* bench(matching): compact-keys cache behavior across L1/L2/LLC sizes (#2073)

Adds a Criterion bench that profiles DeltaSignatureIndex's compact
lookup table at index sizes spanning L1 (~32 KiB), L2 (~512 KiB),
LLC (~32 MiB), and main memory (~256 MiB), with sequential and
scattered probe access patterns.

The bench supplies the evidence needed to decide whether a packed
(rsum_low | bucket_idx) layout (#2072) would meaningfully improve
cache behavior over the current 8-byte slot layout. Top-of-file
comments document the perf stat and cachegrind invocations and the
favorable / unfavorable thresholds that should inform the decision.

Production code is unchanged. The bench-internal feature gains three
read-only accessors on DeltaSignatureIndex (lookup_capacity,
lookup_bytes, lookup_probe) so the bench can isolate the open-
addressed probe chain from the surrounding match pipeline.

* style(matching): apply rustfmt to compact_keys_cache bench

* style(matching): inline MAX_ENTRIES_ENV in format string
oferchen added a commit that referenced this pull request Aug 24, 2026
…2073) (#4188)

* bench(matching): compact-keys cache behavior across L1/L2/LLC sizes (#2073)

Adds a Criterion bench that profiles DeltaSignatureIndex's compact
lookup table at index sizes spanning L1 (~32 KiB), L2 (~512 KiB),
LLC (~32 MiB), and main memory (~256 MiB), with sequential and
scattered probe access patterns.

The bench supplies the evidence needed to decide whether a packed
(rsum_low | bucket_idx) layout (#2072) would meaningfully improve
cache behavior over the current 8-byte slot layout. Top-of-file
comments document the perf stat and cachegrind invocations and the
favorable / unfavorable thresholds that should inform the decision.

Production code is unchanged. The bench-internal feature gains three
read-only accessors on DeltaSignatureIndex (lookup_capacity,
lookup_bytes, lookup_probe) so the bench can isolate the open-
addressed probe chain from the surrounding match pipeline.

* style(matching): apply rustfmt to compact_keys_cache bench

* style(matching): inline MAX_ENTRIES_ENV in format string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant