Skip to content

Parameterize the vector result benchmarks on implementation and function#139423

Merged
thecoop merged 8 commits intoelastic:mainfrom
thecoop:parameterized-vector-benchmarks
Dec 17, 2025
Merged

Parameterize the vector result benchmarks on implementation and function#139423
thecoop merged 8 commits intoelastic:mainfrom
thecoop:parameterized-vector-benchmarks

Conversation

@thecoop
Copy link
Copy Markdown
Member

@thecoop thecoop commented Dec 12, 2025

This makes it a lot more scalable, so more functions can be added without adding more test methods.

So that the benchmark tests continue to work, the random data generation is pulled out into VectorData classes that can be re-used across several different Benchmark classes for specific implementations, to ensure the results are still as expected.

@thecoop thecoop added >test Issues or PRs that are addressing/adding tests :Search Relevance/Vectors Vector search labels Dec 12, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Dec 12, 2025
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Copy Markdown
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Some small comments but look good to me

float vec2CorrectionConstant;
float scoreCorrectionConstant;
@Param
public Implementation implementation;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

IOUtils.rm(path);
}
@Param
public Function function;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nice!

@Benchmark
public float squareDistanceNativeQuery() throws IOException {
return nativeSqrScorerQuery.score(1);
public float scoreQuery() throws IOException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if these are run on Java 21? (supportsHeapSegments() returns false?)
Is there a way to filter these benchmarks out?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method will throw an exception (NPE in this case), and the test will just be ignored by JMH

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit brutal :D but if it works...

@thecoop thecoop requested a review from ldematte December 12, 2025 16:38
Copy link
Copy Markdown
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'd like for @ChrisHegarty to give it a look too.
I remember he was thinking at a naming convention or another way to run a subset of benchmarks -- JMH uses pattern matching on the function names, so being consisten pays.
Adding parameters for dimensions like implementation or function might help here, as they can be used as "filters" (e.g. just run all the benchmarks for native and dot product).

Also, do you have an example of what the output will look like?

@ChrisHegarty
Copy link
Copy Markdown
Contributor

I remember he was thinking at a naming convention or another way to run a subset of benchmarks -- JMH uses pattern matching on the function names, so being consisten pays.
..
Also, do you have an example of what the output will look like?

Right. I think that the refactoring is probably ok, but I'd like to see how what the output looks like, and how we can more easily select subsets with various regex patterns.

@thecoop
Copy link
Copy Markdown
Member Author

thecoop commented Dec 17, 2025

This command:

./gradlew -Druntime.java=25 -p benchmarks run --args 'VectorScorerInt7uBenchmark -p dims=96,1024 -p function=DOT_PRODUCT'

produces this output:

Benchmark                              (dims)   (function)  (implementation)   Mode  Cnt   Score    Error   Units
VectorScorerInt7uBenchmark.score           96  DOT_PRODUCT            SCALAR  thrpt    5  30.679 ±  0.747  ops/us
VectorScorerInt7uBenchmark.score           96  DOT_PRODUCT            LUCENE  thrpt    5  74.437 ±  4.182  ops/us
VectorScorerInt7uBenchmark.score           96  DOT_PRODUCT            NATIVE  thrpt    5  60.110 ±  4.005  ops/us
VectorScorerInt7uBenchmark.score         1024  DOT_PRODUCT            SCALAR  thrpt    5   3.178 ±  2.831  ops/us
VectorScorerInt7uBenchmark.score         1024  DOT_PRODUCT            LUCENE  thrpt    5  13.406 ±  0.825  ops/us
VectorScorerInt7uBenchmark.score         1024  DOT_PRODUCT            NATIVE  thrpt    5  23.472 ± 16.359  ops/us
VectorScorerInt7uBenchmark.scoreQuery      96  DOT_PRODUCT            LUCENE  thrpt    5  60.697 ± 21.170  ops/us
VectorScorerInt7uBenchmark.scoreQuery      96  DOT_PRODUCT            NATIVE  thrpt    5  57.546 ±  8.331  ops/us
VectorScorerInt7uBenchmark.scoreQuery    1024  DOT_PRODUCT            LUCENE  thrpt    5  12.945 ±  3.980  ops/us
VectorScorerInt7uBenchmark.scoreQuery    1024  DOT_PRODUCT            NATIVE  thrpt    5  34.916 ±  2.796  ops/us

@thecoop thecoop force-pushed the parameterized-vector-benchmarks branch from e9d4e7f to bff2990 Compare December 17, 2025 10:20
@thecoop thecoop force-pushed the parameterized-vector-benchmarks branch from bff2990 to 348cd94 Compare December 17, 2025 10:21
@ldematte
Copy link
Copy Markdown
Contributor

Thanks for the output. I think it is nice, as it gives us a way (using parameters) to filter/execute benchmarks over multiple dimensions (function, like you did in the example, but also implementation).
We could for example easily filter for int7 bulk (both via name) dot product (param) native (param). That would be more difficult with just names.

@thecoop thecoop merged commit 8cccfd9 into elastic:main Dec 17, 2025
35 checks passed
@thecoop thecoop deleted the parameterized-vector-benchmarks branch December 17, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch >test Issues or PRs that are addressing/adding tests v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants