Skip to content

bench(spann): add a Criterion harness for the distance kernels - #782

Open
ohdearquant wants to merge 1 commit into
ruvnet:mainfrom
ohdearquant:bench/spann-distance-kernels
Open

bench(spann): add a Criterion harness for the distance kernels#782
ohdearquant wants to merge 1 commit into
ruvnet:mainfrom
ohdearquant:bench/spann-distance-kernels

Conversation

@ohdearquant

@ohdearquant ohdearquant commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

Adds a Criterion benchmark harness for ruvector-spann's distance module. The
crate has distance kernels in src/distance.rs: l2_squared is on the index
hot path (src/kmeans.rs, src/index.rs), and cosine_distance is a public
kernel with no production call site today, covered by the same harness. Until
now the crate had 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. The only Cargo.toml additions are under
[dev-dependencies] (criterion, rand, both at the workspace-pinned
versions) plus the [[bench]] declaration.

Design notes

  • One Criterion group per public distance function, parameterized over
    dimensions 128 / 384 / 768 / 1536.
  • Operands come from a seeded StdRng (gen_range(-1.0..1.0)), not constant
    fills, so runs are reproducible while still exercising data-dependent
    behaviour. Several existing benches elsewhere in the workspace use
    constant-fill vectors, which say nothing about data dependence; this harness
    deliberately does not inherit that.
  • black_box on both inputs and outputs.

Verification

  • cargo bench -p ruvector-spann --bench distance -- --test: all 8 cases
    print Success.
  • cargo fmt --all -- --check: clean.
  • cargo clippy -p ruvector-spann --all-targets: no Clippy diagnostic names
    the new bench file. Pre-existing, unrelated output remains: Cargo's
    workspace profile-ignored warnings and the ruvector-attention bench/bin
    double-target warning, both untouched here.

Why now

#763 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.

Add a Criterion harness for the l2_squared and cosine_distance
kernels in ruvector-spann, covering dimensions 128/384/768/1536
with seeded random inputs instead of constant fills.
@ohdearquant
ohdearquant marked this pull request as ready for review August 3, 2026 18:08
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