Skip to content

Apache Lucene open-source search software

Eliminate redundant cardinality() pass in MaxScoreBulkScorer (#15971)

Prithvidbbdca8ffd2d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b055ac1277c..f389beb3f23 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -318,6 +318,12 @@ Optimizations
---------------------
* GITHUB#15861: Optimise PhraseScorer by short circuiting non competitive documents in TOP_SCORES mode. (Prithvi S)
+* GITHUB#15868: Optimize DisjunctionMaxBulkScorer by reusing the inner LeafCollector across
+ sub-scorers and resetting windowScores inline during replay instead of Arrays.fill. (Prithvi S)
+
+* Eliminate redundant cardinality() pass in MaxScoreBulkScorer by pre-allocating the
+ doc/score buffer to the max window size. (Prithvi S)
+
* GITHUB#15637: Lazily allocate ByteArrayDataInputs in SegmentTermsEnumFrame#15637 (Misha Dmitriev)
* GITHUB#15718 Skip per-document stored field reads on sorted indices when no stored fields are present (Francisco Fernández Castaño)
@@ -347,9 +353,6 @@ Optimizations
* GITHUB#15970: Reduce memory usage of fields with long terms during segment merges. (Alan Woodward)
-* GITHUB#15868: Optimize DisjunctionMaxBulkScorer by reusing the inner LeafCollector across
- sub-scorers and resetting windowScores inline during replay instead of Arrays.fill. (Prithvi S)
-
* GITHUB#15732: Prevent writing vectors twice during merging HNSW graphs by allowing doing deferred work after calling
merge for vectors is finshed. (Ignacio Vera)
diff --git a/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java
index 9bc732ba19e..81ebc6d0cfe 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java
@@ -51,7 +51,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
private final double[] windowScores = new double[INNER_WINDOW_SIZE];
private final DocAndFloatFeatureBuffer docAndScoreBuffer = new DocAndFloatFeatureBuffer();
- private final DocAndScoreAccBuffer docAndScoreAccBuffer = new DocAndScoreAccBuffer();
+ private final DocAndScoreAccBuffer docAndScoreAccBuffer;
MaxScoreBulkScorer(int maxDoc, List<Scorer> scorers, Scorer filter) throws IOException {
this.maxDoc = maxDoc;
@@ -68,6 +68,8 @@ final class MaxScoreBulkScorer extends BulkScorer {
this.cost = cost;
essentialQueue = DisiPriorityQueue.ofMaxSize(allScorers.length);
maxScoreSums = new double[allScorers.length];
+ docAndScoreAccBuffer = new DocAndScoreAccBuffer();
+ docAndScoreAccBuffer.growNoCopy(INNER_WINDOW_SIZE);
}
// Number of outer windows that have been evaluated
@@ -263,7 +265,6 @@ final class MaxScoreBulkScorer extends BulkScorer {
top = essentialQueue.updateTop();
} while (top.doc < innerWindowMax);
- docAndScoreAccBuffer.growNoCopy(windowMatches.cardinality(0, innerWindowSize));
docAndScoreAccBuffer.size = 0;
windowMatches.forEach(
0,