You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2026/04/29 14:38:13 UTC
(lucene) branch branch_10x updated: Optimize DisjunctionMaxBulkScorer: reuse inner collector and inline score reset (#15868) (#15988)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 4482a4a4aef Optimize DisjunctionMaxBulkScorer: reuse inner collector and inline score reset (#15868) (#15988)
4482a4a4aef is described below
commit 4482a4a4aef491167244ae2a96490da24459750e
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Wed Apr 29 16:38:06 2026 +0200
Optimize DisjunctionMaxBulkScorer: reuse inner collector and inline score reset (#15868) (#15988)
Co-authored-by: Prithvi <pr...@gmail.com>
---
lucene/CHANGES.txt | 4 ++
.../lucene/search/DisjunctionMaxBulkScorer.java | 63 +++++++++++-----------
2 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index bb420e617ed..aff368fabb9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -95,9 +95,13 @@ 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)
+
Bug Fixes
---------------------
* GITHUB#15754: Fix HTMLStripCharFilter to prevent tags from incorrectly consuming subsequent
diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java
index 464b32b72e7..859673e399c 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java
@@ -17,7 +17,6 @@
package org.apache.lucene.search;
import java.io.IOException;
-import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.apache.lucene.util.Bits;
@@ -45,6 +44,32 @@ final class DisjunctionMaxBulkScorer extends BulkScorer {
private final float[] windowScores = new float[WINDOW_SIZE];
private final PriorityQueue<BulkScorerAndNext> scorers;
private final SimpleScorable topLevelScorable = new SimpleScorable();
+ private int windowMin;
+
+ /**
+ * Reusable inner {@link LeafCollector} that collects matches into the window bitset and scores
+ * array. This avoids allocating a new anonymous collector object per sub-scorer per window.
+ */
+ private final LeafCollector innerCollector =
+ new LeafCollector() {
+
+ private Scorable scorer;
+
+ @Override
+ public void setScorer(Scorable scorer) throws IOException {
+ this.scorer = scorer;
+ if (topLevelScorable.minCompetitiveScore != 0f) {
+ scorer.setMinCompetitiveScore(topLevelScorable.minCompetitiveScore);
+ }
+ }
+
+ @Override
+ public void collect(int doc) throws IOException {
+ final int delta = doc - windowMin;
+ windowMatches.set(delta);
+ windowScores[delta] = Math.max(windowScores[delta], scorer.score());
+ }
+ };
DisjunctionMaxBulkScorer(List<BulkScorer> scorers) {
if (scorers.size() < 2) {
@@ -65,51 +90,27 @@ final class DisjunctionMaxBulkScorer extends BulkScorer {
BulkScorerAndNext top = scorers.top();
while (top.next < max) {
- final int windowMin = Math.max(top.next, min);
+ windowMin = Math.max(top.next, min);
final int windowMax = MathUtil.unsignedMin(max, windowMin + WINDOW_SIZE);
// First compute matches / scores in the window
do {
- top.next =
- top.scorer.score(
- new LeafCollector() {
-
- private Scorable scorer;
-
- @Override
- public void setScorer(Scorable scorer) throws IOException {
- this.scorer = scorer;
- if (topLevelScorable.minCompetitiveScore != 0f) {
- scorer.setMinCompetitiveScore(topLevelScorable.minCompetitiveScore);
- }
- }
-
- @Override
- public void collect(int doc) throws IOException {
- final int delta = doc - windowMin;
- windowMatches.set(delta);
- windowScores[delta] = Math.max(windowScores[delta], scorer.score());
- }
- },
- acceptDocs,
- windowMin,
- windowMax);
+ top.next = top.scorer.score(innerCollector, acceptDocs, windowMin, windowMax);
top = scorers.updateTop();
} while (top.next < windowMax);
- // Then replay
+ // Then replay, resetting windowScores entries inline to avoid a full Arrays.fill
collector.setScorer(topLevelScorable);
for (int windowDoc = windowMatches.nextSetBit(0);
windowDoc != DocIdSetIterator.NO_MORE_DOCS;
windowDoc = windowMatches.nextSetBit(windowDoc + 1)) {
- int doc = windowMin + windowDoc;
topLevelScorable.score = windowScores[windowDoc];
- collector.collect(doc);
+ windowScores[windowDoc] = 0f;
+ collector.collect(windowMin + windowDoc);
}
- // Finally clean up state
+ // Only the bitset needs clearing; windowScores entries were reset during replay above.
windowMatches.clear();
- Arrays.fill(windowScores, 0f);
}
return top.next;