kkewwei commented on code in PR #16849:
URL: https://github.com/apache/lucene/pull/16849#discussion_r4290872625


##########
lucene/core/src/java/org/apache/lucene/util/BitSetIterator.java:
##########
@@ -96,12 +99,18 @@ public long cost() {
   @Override
   public int docIDRunEnd() {
     assert doc != NO_MORE_DOCS;
-    int next = doc + 1;
-    if (next >= length) {
-      return length;
+    // Called once per window by DenseConjunctionBulkScorer: resume from the 
known run end and
+    // bound the scan, otherwise a long run is rescanned on every call, which 
is quadratic.
+    if (doc < runStart || doc >= runEnd) {

Review Comment:
   we don't need `runStart`. I noticed that in the tests, there are cases where 
the doc moves backward—which is where `runStart` comes into play, but according 
to the Lucene specification, doc should not move backward.



##########
lucene/core/src/java/org/apache/lucene/util/BitSetIterator.java:
##########
@@ -51,9 +51,12 @@ public static SparseFixedBitSet 
getSparseFixedBitSetOrNull(DocIdSetIterator iter
     return getBitSet(iterator, SparseFixedBitSet.class);
   }
 
+  static final int MAX_RUN_END_SCAN = 1 << 16;

Review Comment:
   `MAX_RUN_END_SCAN` should also be removed?



##########
lucene/core/src/test/org/apache/lucene/search/TestDenseConjunctionBulkScorer.java:
##########
@@ -1394,4 +1395,121 @@ public void collect(int doc) throws IOException {
     scorer.score(collector, null, 0, DocIdSetIterator.NO_MORE_DOCS);
     assertEquals(expected.cardinality(), collector.count);
   }
+
+  public void testLongRunWithLiveDocsIsScannedOnce() throws IOException {

Review Comment:
   Maybe we should only add tests to `TestBitSetIterator`, no need to add tests 
to `TestDenseConjunctionBulkScorer`.



-- 
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