Skip to content

bench(diskann): add a Criterion harness for the distance kernels - #783

Open
ohdearquant wants to merge 2 commits into
ruvnet:mainfrom
ohdearquant:bench/diskann-distance-kernels
Open

bench(diskann): add a Criterion harness for the distance kernels#783
ohdearquant wants to merge 2 commits into
ruvnet:mainfrom
ohdearquant:bench/diskann-distance-kernels

Conversation

@ohdearquant

@ohdearquant ohdearquant commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

Adds a Criterion benchmark harness for ruvector-diskann's distance module.
The crate has four feature-agnostic public distance kernels in
src/distance.rs (l2_squared, scalar_l2_squared, inner_product,
pq_asymmetric_distance) and until now no benches/ directory, no [[bench]]
target, and no criterion dev-dependency, so a performance change to this
crate cannot be measured inside the crate itself.

No behaviour change. Cargo.toml gains criterion under [dev-dependencies]
(workspace-pinned) and the [[bench]] declaration; rand was already a
dependency and needed nothing.

Design notes

  • One Criterion group per kernel, parameterized over dimensions
    128 / 384 / 768 / 1536.
  • simd_l2_squared and the wasm_simd128_* variants are deliberately not
    benched: they are gated behind feature = "simd" / target_arch = "wasm32"
    and are not part of the default-feature build, so a default cargo bench
    could not reach them anyway. The harness benches what the active feature set
    provides.
  • Operands from a seeded StdRng (gen_range(-1.0..1.0)) rather than constant
    fills; black_box on inputs and outputs.

Verification

  • cargo bench -p ruvector-diskann --bench distance -- --test: all 16 cases
    print Success.
  • cargo fmt --all -- --check: clean (after one formatting pass on the new
    file).
  • cargo clippy -p ruvector-diskann --all-targets: finishes with no warnings
    attributed to this crate or the new bench file.

Why now

#766 proposes an optional distance backend for this crate and currently has no
way to carry before/after numbers. This harness is the missing instrument, kept
as its own PR so the instrument and the change it would measure are reviewed
separately.


Note on this PR's CI. Tests (core-and-rest) is red on every branch in this repository,
including main: the job is cancelled at its 240-minute cap while still compiling and never
reaches the test phase. #786 restores the exclusion list that the shard's packages: value loses
to a shell comment, #784 unblocks the ruvector-filter test target that the compiler cannot
finish, and #787 fixes a deadlock waiting behind both. That failure is not caused by this branch.

Criterion harness for the four public distance kernels (l2_squared,
scalar_l2_squared, inner_product, pq_asymmetric_distance), parameterized
over dimensions 128/384/768/1536 with seeded-RNG operands.
…dimension

The pq_asymmetric_distance fixture built dim codes and dim*256 lookup
entries, but the kernel's unit of work is the PQ subspace count M
(src/distance.rs:415), not the embedding dimension. ProductQuantizer::encode
emits exactly m codes and build_distance_table allocates m*256 entries
(src/pq.rs:173,206). Labelling M as dim inflated the loop count and
lookup-table working set ~8x versus the realistic dsub=8 configuration
matching the crate's exercised shape (D=32, M=4 — src/index.rs:847,852).

Parametrize by (D, M) pairs at dsub=8: D=128->M=16, D=384->M=48,
D=768->M=96, D=1536->M=192, with case labels d{dim}_m{m} making the
measured unit of work explicit in Criterion output.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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