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-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org