diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java index 66e72bf11c3b..1b0e034065e3 100644 --- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java +++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java @@ -33,6 +33,7 @@ import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.MMapDirectory; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.VectorUtil; import org.apache.lucene.util.hnsw.RandomVectorScorer; import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier; import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer; @@ -91,6 +92,11 @@ public void init() throws IOException { .getRandomVectorScorerSupplier(DOT_PRODUCT, vectorValues) .scorer(); scorer.setScoringOrdinal(0); + + // Pollute call site! + for (int i = 0; i < 10_000_000; i++) { + VectorUtil.dotProduct(vec1, vec2); + } } @TearDown @@ -109,6 +115,17 @@ public float binaryDotProductMemSeg() throws IOException { return scorer.score(1); } + @Benchmark + @Fork( + jvmArgsPrepend = { + "--add-modules=jdk.incubator.vector", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:CompilerDirectivesFile=lucene/benchmark-jmh/src/resources/vector-directives.json" + }) + public float binaryDotProductMemSegWithVectorDirectives() throws IOException { + return scorer.score(1); + } + static KnnVectorValues vectorValues( int dims, int size, IndexInput in, VectorSimilarityFunction sim) throws IOException { return new OffHeapByteVectorValues.DenseOffHeapVectorValues( diff --git a/lucene/benchmark-jmh/src/resources/vector-directives.json b/lucene/benchmark-jmh/src/resources/vector-directives.json new file mode 100644 index 000000000000..753207255ec2 --- /dev/null +++ b/lucene/benchmark-jmh/src/resources/vector-directives.json @@ -0,0 +1,9 @@ +[ + { + "match": [ "org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport::*" ], + "inline": [ + "-org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport$ArrayLoader::*", + "-org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport$MemorySegmentLoader::*" + ] + } +]