Skip to content

Commit

Permalink
Use hppc IntIntHashMap to avoid Integer box/unbox when remapping vect…
Browse files Browse the repository at this point in the history
…or ordinals during merge (#12950)
  • Loading branch information
msokolov authored and Michael Sokolov committed Dec 15, 2023
1 parent 26ba2ff commit 7d62b23
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;

import java.io.IOException;
import java.util.Map;
import org.apache.lucene.codecs.HnswGraphProvider;
import org.apache.lucene.codecs.KnnVectorsReader;
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
Expand All @@ -30,9 +29,9 @@
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.hppc.IntIntHashMap;

/**
* This selects the biggest Hnsw graph from the provided merge state and initializes a new
Expand Down Expand Up @@ -172,7 +171,7 @@ protected final int[] getNewOrdMapping(
"Unexpected vector encoding: " + fieldInfo.getVectorEncoding());
}

Map<Integer, Integer> newIdToOldOrdinal = CollectionUtil.newHashMap(initGraphSize);
IntIntHashMap newIdToOldOrdinal = new IntIntHashMap(initGraphSize);
int oldOrd = 0;
int maxNewDocID = -1;
for (int oldId = initializerIterator.nextDoc();
Expand All @@ -192,9 +191,10 @@ protected final int[] getNewOrdMapping(
for (int newDocId = mergedVectorIterator.nextDoc();
newDocId <= maxNewDocID;
newDocId = mergedVectorIterator.nextDoc()) {
if (newIdToOldOrdinal.containsKey(newDocId)) {
int hashDocIndex = newIdToOldOrdinal.indexOf(newDocId);
if (newIdToOldOrdinal.indexExists(hashDocIndex)) {
initializedNodes.set(newOrd);
oldToNewOrdinalMap[newIdToOldOrdinal.get(newDocId)] = newOrd;
oldToNewOrdinalMap[newIdToOldOrdinal.indexGet(hashDocIndex)] = newOrd;
}
newOrd++;
}
Expand Down

0 comments on commit 7d62b23

Please sign in to comment.