-
Notifications
You must be signed in to change notification settings - Fork 140
Optimizes reducelanes in diversityCalculation of PQVectors, for Euclidean function #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a991b33 to
dd1c332
Compare
|
This PR does successfully remove the calls to reduceLanes from the inside of the loop iterating over the subspaces the Euclidean case. I do have a concern about applying this pattern to one specific case but leaving the handling of other cases as is, leaving the code with 2 different implementations for the same problem. Some questions:
|
|
@MarkWolters, thank you very much for the feedback. I can make the changes to dotProduct methods and to function calls in scoreFunctionFor() |
|
@shyla226 please be aware that in order to pass the automated GitHub action regression test any pull request must come from a branch inside the datastax/jvector repository and not a fork of the repository. So while I am willing to review the PR from a fork and provide commentary, in order for it to pass the requirements for merging it will have to be a branch and not a fork. |
|
@MarkWolters, Sounds good! I will create a branch |
|
@shyla226 I don't think you'll have sufficient permissions to push a new branch to the repository. For now you can keep the changes on a fork and they can be reviewed there while we come up with a solution to this issue. |
…ctionFor 2) For Euclidean, Dot Product & Cosine methods 3) Added a new benchmark, PQDistanceCalculationMutableVectorBenchmark, which uses Mutable Vectors, replicating code in PQDistanceCalculationVectorBenchmark
|
@MarkWolters , I have added new functions to include dotproduct & cosine for diversityFunction. |
fixed a bug in the name
|
Thanks @shyla226, I will review the updated code asap |
silly error in jdk11 test path
|
Thank you very much @MarkWolters . With the changes, when M=64, dot product shows ~30% reduction in latency & COSINE shows ~43% reduction |
|
@MarkWolters sorry, accidentally closed it! I will update the test setup used in the description above. |
|
@MarkWolters, I have addressed the issue with the 2 failed checks and tested the code changes on Windows server |
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 aforloop (viaVectorUtil.squareL2Distance). Modification in this pull request moves call toreduceLanes()outside theforloop.Change proposed here was tested with the benchmark,
PQDistanceCalculationBenchmark.diversityCalculationWith this benchmark, ~18% reduction in time was observed when M=64 and ~22% when M=192.
Code modifications:
pqDiversityEuclideaninVectorUtilSupportand its corresponding implementationsforloop inPQVectors.diversityFunctionForand moved it intopqDiversityEuclideanFloatVector.reducelanes()outside theforloopTest 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
New changes
I have modified the code to include dot product & cosine functions and implemented similar changes for scoreFunctionFor.
With the changes applied to scoreFunctionFor, when M=64: dot product shows ~30% reduction in latency & cosine shows ~43% reduction.
I can add data points for other subspace counts, if required.
Code modifications:
pqScoreEuclidean, pqScoreDotProduct, pqScoreCosineinVectorUtilSupportand its corresponding implementations fordiversityFunctionForscoreFunctionForforloop inPQVectors.diversityFunctionForandPQVectors.scoreFunctionForand moved them into respective functions inPanamaVectorUtilSupportFloatVector.reducelanes()outside theforloopMutablePQVectorsto test thisTest setup:
Jvector version : main branch (as of 2025-10-22)
JDK version : openjdk version "25.0.1" 2025-10-21
Platform : Intel(R) Xeon(R) 6979P
Benchmark :
PQDistanceCalculationMutableVectorBenchmark(Added this by replicatingPQDistanceCalculationBenchmarkto measure performance for MutablePQVectors)