You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "benwtrent (via GitHub)" <gi...@apache.org> on 2023/08/01 13:52:50 UTC
[GitHub] [lucene] benwtrent commented on a diff in pull request #12480: Enhancement 11236 lazy compute similarity score
benwtrent commented on code in PR #12480:
URL: https://github.com/apache/lucene/pull/12480#discussion_r1280674352
##########
lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java:
##########
@@ -31,20 +33,21 @@
public class NeighborArray {
private final boolean scoresDescOrder;
private int size;
-
float[] score;
int[] node;
private int sortedNodeSize;
+ private HashMap<Integer, ScoringFunction> scoringContext;
public NeighborArray(int maxSize, boolean descOrder) {
node = new int[maxSize];
score = new float[maxSize];
this.scoresDescOrder = descOrder;
+ scoringContext = new HashMap<>();
Review Comment:
Pre-allocate to `maxSize`. We should avoid making the hashmap grow as we add things.
##########
lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java:
##########
@@ -111,6 +129,12 @@ public int[] sort() {
private int insertSortedInternal() {
assert sortedNodeSize < size : "Call this method only when there's unsorted node";
int tmpNode = node[sortedNodeSize];
+ // Check if we need to compute score
+ if (scoringContext.containsKey(sortedNodeSize)) {
+ score[sortedNodeSize] = scoringContext.get(sortedNodeSize).calculateScore();
+ scoringContext.remove(sortedNodeSize);
+ }
Review Comment:
You should simplify and only call the map once.
```suggestion
// Check if we need to compute score
ScoringFunction maybeScoringFunction = scoringContext.remove(sortedNodeSize);
if (maybeScoringFunction != null) {
score[sortedNodeSize] = maybeScoringFunction.calculateScore();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org