Optimizes reducelanes in diversityCalculation of PQVectors, for Euclidean function #514
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.
This pull request introduces improvement to Euclidean similarity function in
PQVectors.diversityFunctionFor
. From flamegraph, it is observed that considerable amount of time is spent injdk/incubator/vector/FloatVector.reducelanesTemplate
. This is mainly becauseFloatVector.reducelanes()
is expensive and it is being called inside afor
loop (viaVectorUtil.squareL2Distance
). Modification in this pull request moves call toreduceLanes()
outside thefor
loop.Change proposed here was tested with the benchmark,
PQDistanceCalculationBenchmark.diversityCalculation
With this benchmark, ~18% reduction in time was observed when M=64 and ~22% when M=192.
Code modifications:
pqDiversityEuclidean
inVectorUtilSupport
and its corresponding implementationsfor
loop inPQVectors.diversityFunctionFor
and moved it intopqDiversityEuclidean
FloatVector.reducelanes()
outside thefor
loopTest setup:
Jvector version : main branch (as of 2025-08-28)
JDK version : openjdk version "24.0.2" 2025-07-15
Platform : INTEL(R) XEON(R) PLATINUM 8592+
Benchmark : PQDistanceCalculationBenchmark.diversityCalculation