Apache Lucene open-source search software
Fewer virtual calls to enhance performance (#14851)
kkewwei9801775f3eb7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 01938ae6347..8bd43b06335 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -47,6 +47,7 @@ Optimizations---------------------* GITHUB#14011: Reduce allocation rate in HNSW concurrent merge. (Viliam Durina)* GITHUB#14022: Optimize DFS marking of connected components in HNSW by reducing stack depth, improving performance and reducing allocations. (Viswanath Kuchibhotla)+* GITHUB#14851: Fewer virtual calls to enhance performance of point queries. (Ke Wei)Bug Fixes---------------------diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.javaindex f509f6100a4..9c991e6b1b4 100644--- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java@@ -246,6 +246,11 @@ public class BKDReader extends PointValues {private final DocIdsWriter docIdsWriter;// if true the tree is balanced, otherwise unbalancedprivate final boolean isTreeBalanced;+ private final IntsRef scratchIntsRef = new IntsRef();++ {+ assert scratchIntsRef.offset == 0;+ }private BKDPointTree(IndexInput innerNodes,@@ -783,10 +788,11 @@ public class BKDReader extends PointValues {return;}visitor.grow(count);+if (r == PointValues.Relation.CELL_INSIDE_QUERY) {- for (int i = 0; i < count; ++i) {- visitor.visit(scratchIterator.docIDs[i]);- }+ scratchIntsRef.ints = scratchIterator.docIDs;+ scratchIntsRef.length = count;+ visitor.visit(scratchIntsRef);return;}} else {@@ -849,9 +855,9 @@ public class BKDReader extends PointValues {visitor.grow(count);if (r == PointValues.Relation.CELL_INSIDE_QUERY) {- for (int i = 0; i < count; ++i) {- visitor.visit(scratchIterator.docIDs[i]);- }+ scratchIntsRef.ints = scratchIterator.docIDs;+ scratchIntsRef.length = count;+ visitor.visit(scratchIntsRef);return;}} else {