diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 28aeee6b0e4f..ce14c37d9d2d 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -129,6 +129,8 @@ Optimizations --------------------- * GITHUB#15140: Optimize TopScoreDocCollector with TernaryLongHeap for improved performance over Binary-LongHeap. (Ramakrishna Chilaka) +* GITHUB#15163: Use TernaryLongHeap in NeighborQueue for faster vector search performance. (Ramakrishna Chilaka) + * GITHUB#14998: Speed up flushing of live docs. (Adrien Grand) Bug Fixes diff --git a/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborQueue.java b/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborQueue.java index 6a473704a85f..86f65ee065e6 100644 --- a/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborQueue.java +++ b/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborQueue.java @@ -17,13 +17,13 @@ package org.apache.lucene.util.hnsw; -import org.apache.lucene.util.LongHeap; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util.TernaryLongHeap; /** - * NeighborQueue uses a {@link LongHeap} to store lists of arcs in an HNSW graph, represented as a - * neighbor node id with an associated score packed together as a sortable long, which is sorted - * primarily by score. The queue provides both fixed-size and unbounded operations via {@link + * NeighborQueue uses a {@link TernaryLongHeap} to store lists of arcs in an HNSW graph, represented + * as a neighbor node id with an associated score packed together as a sortable long, which is + * sorted primarily by score. The queue provides both fixed-size and unbounded operations via {@link * #insertWithOverflow(int, float)} and {@link #add(int, float)}, and provides MIN and MAX heap * subclasses. */ @@ -48,7 +48,7 @@ long apply(long v) { abstract long apply(long v); } - private final LongHeap heap; + private final TernaryLongHeap heap; private final Order order; // Used to track the number of neighbors visited during a single graph traversal @@ -57,7 +57,7 @@ long apply(long v) { private boolean incomplete; public NeighborQueue(int initialSize, boolean maxHeap) { - this.heap = new LongHeap(initialSize); + this.heap = new TernaryLongHeap(initialSize); this.order = maxHeap ? Order.MAX_HEAP : Order.MIN_HEAP; }