diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 8ef68343e5fb..34e5058c7bad 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -131,6 +131,9 @@ Improvements Optimizations --------------------- +* Eliminate redundant cardinality() pass in MaxScoreBulkScorer by pre-allocating the + doc/score buffer to the max window size. (Prithvi S) + * GITHUB#15681, GITHUB#15833: Replace pre-sized array or empty array with lambda expression to call Collection#toArray. (Zhou Hui) * GITHUB#13782: Replace handwritten loops compare with Arrays.compareUnsigned in TermsEnum and TermsEnumFrame classes. (Zhou Hui) 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 9bc732ba19e3..81ebc6d0cfe7 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 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 @@ private void scoreInnerWindowMultipleEssentialClauses( top = essentialQueue.updateTop(); } while (top.doc < innerWindowMax); - docAndScoreAccBuffer.growNoCopy(windowMatches.cardinality(0, innerWindowSize)); docAndScoreAccBuffer.size = 0; windowMatches.forEach( 0,