costin commented on code in PR #16141:
URL: https://github.com/apache/lucene/pull/16141#discussion_r3315513065


##########
lucene/core/src/java/org/apache/lucene/search/Weight.java:
##########
@@ -228,9 +230,12 @@ public long cost() {
    * @lucene.internal
    */
   protected static class DefaultBulkScorer extends BulkScorer {
+    private static final int WINDOW_SIZE = 1 << 12;

Review Comment:
   Done, switched DefaultBulkScorer to reuse 
DenseConjunctionBulkScorer.WINDOW_SIZE.



##########
lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java:
##########
@@ -147,6 +147,10 @@ public float score() throws IOException {
     return score;
   }
 
+  boolean canBulkCollectDocIdStream() {
+    return scoreMode != ScoreMode.TOP_SCORES;
+  }

Review Comment:
   No AssertingScorer change needed: the current targeted tests pass, and the 
optimized path remains guarded to non-TOP_SCORES ConstantScoreScorer.



##########
lucene/core/src/java/org/apache/lucene/search/Weight.java:
##########
@@ -300,6 +310,27 @@ private static void scoreIterator(
       }
     }
 
+    private void scoreIteratorIntoBitSet(
+        LeafCollector collector, Bits acceptDocs, DocIdSetIterator iterator, 
int max)
+        throws IOException {
+      for (int doc = iterator.docID(); doc < max; ) {
+        int windowBase = doc;
+        int windowMax = MathUtil.unsignedMin(max, windowBase + WINDOW_SIZE);
+
+        assert windowMatches.scanIsEmpty();
+        iterator.intoBitSet(windowMax, windowMatches, windowBase);
+
+        if (acceptDocs != null) {

Review Comment:
   Done, the bitset path now skips both live-doc masking and DocIdStream 
collection when the window is empty.



##########
lucene/core/src/java/org/apache/lucene/search/Weight.java:
##########
@@ -277,7 +282,12 @@ public int score(LeafCollector collector, Bits acceptDocs, 
int min, int max)
       // iterator implementations.
       if (twoPhase == null && competitiveIterator == null) {
         // Optimize simple iterators with collectors that can't skip
-        scoreIterator(collector, acceptDocs, iterator, max);
+        if (scorer instanceof ConstantScoreScorer constantScoreScorer
+            && constantScoreScorer.canBulkCollectDocIdStream()) {
+          scoreIteratorIntoBitSet(collector, acceptDocs, iterator, max);

Review Comment:
   I left out the density gate intentionally: the benchmark still shows gains 
at 1% density, and DenseConjunctionBulkScorer’s threshold is for multi-clause 
bitset intersections. The new empty-window skip handles sparse gaps without 
disabling the measured sparse-case win.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to