Improve performance and readability of recall and precision measurements#647
Open
Improve performance and readability of recall and precision measurements#647
Conversation
Contributor
|
Before you submit for review:
If you did not complete any of these, then please explain below. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR optimizes$O(N^2)$ list-scanning to $O(N)$ Set-based lookups and reducing object allocation overhead by interacting directly with primitive
AccuracyMetricsto improve the performance and readability of recall and precision measurements. The primary focus is shifting fromNodeScorearrays.Key changes
Logic cleanup and "dead code" removal
topKCorrect(List, List, ...)signature, consolidating logic into a single private method that operates directly onSearchResult.if (gtView.size() > retrieved.size())branch. Due to existing guard clauses (kGT <= kRetrievedandkRetrieved <= retrieved.size()), this condition was mathematically impossible.kparameters.Performance optimizations
List.contains()calls withHashSet.contains(). This moves the core intersection logic from quadratic to linear time complexity.averagePrecisionAtK, replaced thesubList(0, i).contains(p)duplicate check with aHashSetlookup. This transforms the AP calculation from anArrayListcreation in theSearchResultpath. The logic now iterates directly over theNodeScore[]array, significantly reducing GC pressure during large benchmark runs.forloops in high-frequency paths to avoid the object overhead and "setup tax" of the Stream API.Test coverage
IllegalArgumentExceptionstrings remain 1:1 identical to the original implementation to prevent breaking downstream error-parsing.Performance results
Benchmarks were conducted using 10,000 queries on the
gecko-100kdataset (768 dimensions).While the benefit is negligible for$K=10$ , the optimization becomes critical as $K$ increases. The reduction in AP measurement time is particularly significant as it eliminates the $O(K^2)$ complexity previously caused by nested sublist scans.
Notes / limitations
Listallocations, it still utilizesHashSet<Integer>. Further gains could be achieved using primitive-specific collections (likeIntHashSet) if necessary in the future.