bench(diskann): add a Criterion harness for the distance kernels - #783
Open
ohdearquant wants to merge 2 commits into
Open
bench(diskann): add a Criterion harness for the distance kernels#783ohdearquant wants to merge 2 commits into
ohdearquant wants to merge 2 commits into
Conversation
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.
ohdearquant
marked this pull request as ready for review
August 3, 2026 18:08
…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>
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.
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 nobenches/directory, no[[bench]]target, and no
criteriondev-dependency, so a performance change to thiscrate cannot be measured inside the crate itself.
No behaviour change.
Cargo.tomlgainscriterionunder[dev-dependencies](workspace-pinned) and the
[[bench]]declaration;randwas already adependency and needed nothing.
Design notes
128 / 384 / 768 / 1536.
simd_l2_squaredand thewasm_simd128_*variants are deliberately notbenched: they are gated behind
feature = "simd"/target_arch = "wasm32"and are not part of the default-feature build, so a default
cargo benchcould not reach them anyway. The harness benches what the active feature set
provides.
StdRng(gen_range(-1.0..1.0)) rather than constantfills;
black_boxon inputs and outputs.Verification
cargo bench -p ruvector-diskann --bench distance -- --test: all 16 casesprint
Success.cargo fmt --all -- --check: clean (after one formatting pass on the newfile).
cargo clippy -p ruvector-diskann --all-targets: finishes with no warningsattributed 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 neverreaches the test phase. #786 restores the exclusion list that the shard's
packages:value losesto a shell comment, #784 unblocks the
ruvector-filtertest target that the compiler cannotfinish, and #787 fixes a deadlock waiting behind both. That failure is not caused by this branch.