You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "costin (via GitHub)" <gi...@apache.org> on 2026/05/28 19:07:29 UTC

[PR] Optimize cached-filter conjunction batching [lucene]

costin opened a new pull request, #16146:
URL: https://github.com/apache/lucene/pull/16146

   This builds on #16141 by allowing `DefaultBulkScorer` to use the `DocIdStream` path for dense no-score conjunctions backed by `BitSetConjunctionDISI`.
   The useful target is cached-filter conjunctions, especially when the cached filter is dense enough for bulk masking to amortize the 4096-doc window cost. Those cases show the clearest wins, up to `2.38x` in this short run.
   
   The uncached comparison is _included to explain the gate_: this is not a general no-score conjunction optimization. 
   Without a cached FixedBitSet, the conjunction can't use intoBitSet / andRange and falls back to per-doc iteration through postings. 
   The gating condition (canBulkIntoBitSet) correctly detects this and doesn't activate.Uncached results are mostly neutral/noisy, so the implementation only enables this path for `BitSetConjunctionDISI` and keeps sparse/non-bitset conjunctions on the per-doc path.
   
   JMH run:
   
   `CachedFilterConjunctionBenchmark -p docCount=1000000 -p leadSelectivity=0.001,0.03,0.10 -p filterSelectivity=0.01,0.10,0.50,1.0 -p variant=baseline,gated -wi 1 -i 2 -w 1s -r 1s -f 1`
   
   Mode: throughput, units: ops/s, higher is better.
   
   #### Platform: c5a.2xlarge, AVX2, JDK 25, 1M docs
   
   #### Cached filter conjunction
   
     | lead  | filter | baseline (ops/s) | gated (ops/s) | speedup |
     |-------|--------|------------------:|--------------:|--------:|
     | 0.001 | 0.01   |           60,997 |        59,139 | 0.97x   |
     | 0.001 | 0.10   |          110,607 |       114,116 | 1.03x   |
     | 0.001 | 0.50   |          105,088 |       104,365 | 0.99x   |
     | 0.001 | 1.0    |          105,648 |       101,335 | 0.96x   |
     | 0.03  | 0.01   |            3,887 |         3,892 | 1.00x   |
     | 0.03  | 0.10   |            4,765 |        10,416 | **2.19x**   |
     | 0.03  | 0.50   |            2,749 |         8,355 | **3.04x**   |
     | 0.03  | 1.0    |            4,472 |        10,865 | **2.43x**   |
     | 0.10  | 0.01   |            2,526 |         2,557 | 1.01x   |
     | 0.10  | 0.10   |            1,274 |         3,797 | **2.98x**   |
     | 0.10  | 0.50   |              799 |         3,954 | **4.95x**   |
     | 0.10  | 1.0    |            1,299 |         3,968 | **3.05x**   |
   
   #### Uncached filter conjunction
   
     | lead  | filter | baseline (ops/s) | gated (ops/s) | speedup |
     |-------|--------|------------------:|--------------:|--------:|
     | 0.001 | 0.01   |           40,074 |        40,700 | 1.02x   |
     | 0.001 | 0.10   |            8,224 |         9,053 | 1.10x   |
     | 0.001 | 0.50   |           25,071 |        22,442 | 0.90x   |
     | 0.001 | 1.0    |           17,426 |        16,511 | 0.95x   |
     | 0.03  | 0.01   |            5,157 |         5,099 | 0.99x   |
     | 0.03  | 0.10   |            1,547 |         1,530 | 0.99x   |
     | 0.03  | 0.50   |            2,048 |         2,013 | 0.98x   |
     | 0.03  | 1.0    |            3,188 |         3,231 | 1.01x   |
     | 0.10  | 0.01   |            3,315 |         3,248 | 0.98x   |
     | 0.10  | 0.10   |              651 |           657 | 1.01x   |
     | 0.10  | 0.50   |              701 |           684 | 0.98x   |
     | 0.10  | 1.0    |            1,173 |         1,181 | 1.01x   |


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4832903735

   Hey @costin, sorry for the delay in reviewing as the 10.5.0 release took over my life for a bit :). I think this can go into 10.6, so could you move the CHANGES entry?


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4571899340

   @iprithv You're right, thanks for catching this! The direct-forwarding default on `FilterLeafCollector` was too optimistic: it preserves bulk collection performance for pure delegators, but it silently bypasses subclasses that only override `collect(int)`. That is a correctness regression relative to the old `LeafCollector` defaults that I overlooked this the tests passed fully.
   I've added a test to guard against this regression and changed the base default to preserve the existing contract of subclassing instead of shortcutting.
   
   There is one performance-sensitive exception: `ConstantScoreQuery` wraps collectors only to replace the scorer passed via `setScorer`; it does not need per-doc interception. For that case, I added explicit forwarding of `collect(DocIdStream)` and `collectRange` to the wrapped collector so we don’t accidentally erase bulk collection through a pure scorer wrapper.
   
   Reran the benchmarks which still shows the intended benefit for cached dense filters (same setup)
   
   #### Platform: c5a.2xlarge, AVX2, JDK 25, 1M docs
   
   #### Cached filter conjunction
   
     | lead  | filter | baseline (ops/s) | ungated (ops/s) | ungated vs base | gated (ops/s) | gated vs base |
     |-------|--------|------------------:|----------------:|----------------:|--------------:|--------------:|
     | 0.001 |   0.01 |           61,048 |          59,206 |           0.97x |        60,644 |         0.99x |
     | 0.001 |   0.10 |          113,306 |          59,908 |       **0.53x** |       114,313 |         1.01x |
     | 0.001 |   0.50 |          104,766 |          34,116 |       **0.33x** |       102,661 |         0.98x |
     | 0.001 |    1.0 |          106,201 |          30,854 |       **0.29x** |       106,188 |         1.00x |
     |  0.03 |   0.01 |            3,824 |           3,806 |           1.00x |         3,889 |         1.02x |
     |  0.03 |   0.10 |            4,401 |           9,932 |       **2.26x** |         9,264 |     **2.10x** |
     |  0.03 |   0.50 |            2,752 |           8,352 |       **3.03x** |         8,589 |     **3.12x** |
     |  0.03 |    1.0 |            4,498 |          10,612 |       **2.36x** |         9,965 |     **2.22x** |
     |  0.10 |   0.01 |            2,599 |           2,667 |           1.03x |         2,509 |         0.97x |
     |  0.10 |   0.10 |            1,289 |           3,821 |       **2.96x** |         3,792 |     **2.94x** |
     |  0.10 |   0.50 |              813 |           3,881 |       **4.78x** |         3,992 |     **4.91x** |
     |  0.10 |    1.0 |            1,323 |           3,836 |       **2.90x** |         3,930 |     **2.97x** |
   
   #### Uncached filter conjunction
   
     | lead  | filter | baseline (ops/s) | ungated (ops/s) | ungated vs base | gated (ops/s) | gated vs base |
     |-------|--------|------------------:|----------------:|----------------:|--------------:|--------------:|
     | 0.001 |   0.01 |           41,216 |          40,454 |           0.98x |        39,666 |         0.96x |
     | 0.001 |   0.10 |            8,476 |           7,197 |       **0.85x** |         8,076 |         0.95x |
     | 0.001 |   0.50 |           24,548 |          16,146 |       **0.66x** |        22,616 |         0.92x |
     | 0.001 |    1.0 |           23,345 |          18,069 |       **0.77x** |        23,613 |         1.01x |
     |  0.03 |   0.01 |            5,195 |           5,553 |           1.07x |         5,145 |         0.99x |
     |  0.03 |   0.10 |            1,597 |           1,473 |           0.92x |         1,584 |         0.99x |
     |  0.03 |   0.50 |            2,054 |           2,123 |           1.03x |         2,053 |         1.00x |
     |  0.03 |    1.0 |            3,161 |           2,637 |       **0.83x** |         3,254 |         1.03x |
     |  0.10 |   0.01 |            3,223 |           3,306 |           1.03x |         3,362 |         1.04x |
     |  0.10 |   0.10 |              647 |             645 |           1.00x |           651 |         1.01x |
     |  0.10 |   0.50 |              700 |             727 |           1.04x |           683 |         0.98x |
     |  0.10 |    1.0 |            1,163 |             906 |       **0.78x** |         1,168 |         1.00x |


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4833772650

   @romseygeek done!


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4631934256

   Platform: c5a.2xlarge, AMD EPYC 7R32, AVX2, 1M docs, JDK 25, `filtered_optional` (FILTER(cached) + SHOULD(a) + SHOULD(b), minShouldMatch=1, COMPLETE_NO_SCORES)
   
    #### AMD EPYC 7R32 (c5a.2xlarge, AVX2)
   
     | lead | filter | baseline (ops/s) | bulkscorer (ops/s) | cached ratio | baseline (ops/s) | bulkscorer (ops/s) | uncached ratio |
     |------|--------|------------------:|-------------------:|:------------:|------------------:|-------------------:|:--------------:|
     | 0.001 | 0.10 | 68,373 | 68,356 | ~1.0x | 7,925 | 7,757 | ~1.0x |
     | 0.001 | 0.50 | 58,594 | 59,067 | ~1.0x | 19,571 | 18,854 | ~1.0x | 
    | 0.03 | 0.10 | 1,840 | 7,060 | **3.84x** | 1,124 | 1,121 | 1.00x |
     | 0.03 | 0.50 | 1,324 | 8,860 | **6.69x** | 1,156 | 1,071 | 0.93x |
     | 0.10 | 0.10 | 563 | 3,252 | **5.78x** | 451 | 1,965 | **4.36x** |
     | 0.10 | 0.50 | 423 | 3,341 | **7.91x** | 390 | 2,491 | **6.40x** |
     | 0.50 | 0.10 | 404 | 4,571 | **11.31x** | 404 | 2,493 | **6.17x** |
     | 0.50 | 0.50 | 79 | 4,638 | **58.79x** | 79 | 2,940 | **37.22x** |
   
   #### Intel Xeon 8375C (c6i.2xlarge, AVX-512)
   
     | lead | filter | baseline (ops/s) | bulkscorer (ops/s) | cached ratio | baseline (ops/s) | bulkscorer (ops/s) | uncached ratio |
     |------|--------|------------------:|-------------------:|:------------:|------------------:|-------------------:|:--------------:|
     | 0.001 | 0.10 | 80,477 | 86,144 | ~1.0x | 10,141 | 10,462 | ~1.0x |
     | 0.001 | 0.50 | 78,096 | 71,257 | ~1.0x | 24,700 | 26,462 | ~1.0x |
     | 0.03 | 0.10 | 2,077 | 8,869 | **4.27x** | 1,189 | 1,195 | 1.00x |
     | 0.03 | 0.50 | 1,523 | 10,119 | **6.64x** | 1,232 | 1,243 | 1.01x |
     | 0.10 | 0.10 | 596 | 3,908 | **6.56x** | 495 | 2,270 | **4.59x** |
     | 0.10 | 0.50 | 437 | 3,942 | **9.02x** | 428 | 2,917 | **6.82x** |
     | 0.50 | 0.10 | 361 | 5,994 | **16.58x** | 361 | 2,385 | **6.60x** |
     | 0.50 | 0.50 | 83 | 6,325 | **76.22x** | 83 | 3,544 | **42.69x** |


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek merged PR #16146:
URL: https://github.com/apache/lucene/pull/16146


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4620524245

   Very nice.  What do the benchmarks look like now?


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r3320544167


##########
lucene/core/src/java/org/apache/lucene/search/FilterLeafCollector.java:
##########
@@ -42,6 +46,16 @@ public void collect(int doc) throws IOException {
     in.collect(doc);
   }
 
+  @Override

Review Comment:
   `FilterLeafCollector` is meant to let subclasses override `collect(int)` and handle each doc. but with these new methods (`collect(DocIdStream)` and `collectRange`), it just forwards everything directly to `in`. that means the subclass’s `collect(int)` never gets called. so any existing subclass that only overrides `collect(int)` will silently break when bulk collection is used.
   
   I see javadoc saying subclasses should override the new methods too, but that’s not really safe. old code won’t do that, and things will just start giving wrong results without any error.
   
   a safer default would be to break the batch calls into per-doc calls, like:
   
   ```java id="safex1"
   @Override
   public void collect(DocIdStream stream) throws IOException {
       stream.forEach(this::collect);
   }
   
   @Override
   public void collectRange(int min, int max) throws IOException {
       for (int doc = min; doc < max; doc++) {
           collect(doc);
       }
   }
   ```
   
   also noticed the subclasses updated already call `this::collect`. but `FilterLeafCollector` itself doesn’t, so anything not updated will behave incorrectly.
   
   I think this could silently break existing code.
   



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r3340083296


##########
lucene/core/src/java/org/apache/lucene/search/Weight.java:
##########
@@ -290,6 +298,16 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
       return iterator.docID();
     }
 
+    private static boolean canBulkCollectDocIdStream(
+        Scorer scorer, DocIdSetIterator iterator, int min, int max) {
+      if (scorer instanceof ConjunctionScorer conjunctionScorer) {

Review Comment:
   I think we want to avoid having special cases such as this in DefaultBulkScorer.  I'd rather look for more places where we can explicitly use ConstantScoreBulkScorer- for example, the optional-clauses-with-filter case that you add a test for here can use one I think?



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "jimczi (via GitHub)" <gi...@apache.org>.
jimczi commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4611908020

   > also worth looking at https://github.com/apache/lucene/pull/16177 which improves how we handle two-phase iteration which might conflict here?
   
   it is merged now and that should simplify this change significantly. The only change needed is to add the `intoBitSet` optim as part of the two phase iterator of this query. 


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "michaeljmarshall (via GitHub)" <gi...@apache.org>.
michaeljmarshall commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r4138521657


##########
lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java:
##########
@@ -262,13 +264,57 @@ assert assertItersOnSameDoc()
       return doNext(lead.advance(target));
     }
 
+    @Override
+    public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
+      assert offset <= docID() : "offset=" + offset + " docID()=" + docID() + " upTo=" + upTo;
+      int doc = docID();
+      if (doc >= upTo) {
+        return;
+      }
+
+      // Bulk masking has fixed per-window cost; sparse leads are cheaper to advance per doc.
+      if (lead.cost() < bitSet.length()) {
+        super.intoBitSet(upTo, bitSet, offset);
+        return;
+      }
+
+      int bulkUpTo = Math.min(upTo, minLength);
+      long destinationEnd = (long) offset + bitSet.length();
+      if (destinationEnd < bulkUpTo) {
+        bulkUpTo = (int) destinationEnd;
+      }
+
+      if (doc < bulkUpTo) {
+        if (scratch == null || scratch.length() != bitSet.length()) {
+          scratch = new FixedBitSet(bitSet.length());
+        } else {
+          scratch.clear();
+        }
+
+        lead.intoBitSet(bulkUpTo, scratch, offset);
+        for (BitSet bitSetMask : bitSets) {
+          bitSetMask.applyMask(scratch, offset);
+        }
+        bitSet.or(scratch);
+
+        doNext(lead.docID());
+      }
+
+      if (docID() < upTo) {
+        super.intoBitSet(upTo, bitSet, offset);
+      }
+    }
+
     private int doNext(int doc) throws IOException {
       advanceLead:
       for (; ; doc = lead.nextDoc()) {
         if (doc >= minLength) {
           if (doc != NO_MORE_DOCS) {
             lead.advance(NO_MORE_DOCS);
           }
+          for (BitSetIterator iterator : bitSetIterators) {
+            iterator.setDocId(NO_MORE_DOCS);
+          }

Review Comment:
   IIUC, this is a bug fix. Without this, the sub-iterators could be in a state where they were not all on the same doc at the same time for `NO_MORE_DOCS`.



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4709928197

   Hi @costin, can you resolve the conflicts here? 


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4602395093

   > Shouldn't the query cache be going through ConstantScoreScorerSupplier/ConstantScoreBulkScorer now?
   
   I've reverted the instanceof check and kept `DefaultBulkScorer` generic and routed the relevant no-score fallback through `ConstantScoreBulkScorer`.
   This avoids the earlier `DefaultBulkScorer` special-case while still enabling batching for cached bitset filters.
   
   I've moved the gating as part of `BitSetConjunctionDISI.intoBitSet()` which decides locally whether the bulk bitset path is worth using: sparse leads fall back to per-doc iteration, while denser leads use the bulk masking path.
   I've put in place two gates:
     - Gate 1:  ConstantScoreBulkScorer (windowed): conjunction match ≥ 8K docs
     - Gate 2: BitSetConjunctionDISI.intoBitSet: lead match ≥ 4k docs
   
   The goal was to avoid divergence between the conjunction and lead cost (e.g. conjuction has 10K matching docs but BSCDISI has very sparse iterator that is suitable to per-doc)
   
   Updated the benchmark results - here we're testing FILTER + SHOULD + SHOULD (vs FILTER+FILTER in the previous one) to activate the filteredOptionalBulkScorer() path  and added test for the query shape where this applies:
   
   cached = filter pre-warmed in LRUQueryCache as FixedBitSet
   uncached = filter evaluated from postings each time
   Query: `FILTER(cached) + SHOULD(a) + SHOULD(b), minShouldMatch=1, COMPLETE_NO_SCORES`
   
   Benchmark running on AMD EPYC c5a.2xlarge, AVX2, JDK 25
   
    | lead | filter | baseline (ops/s) | cached (ops/s) | cached ratio | baseline (ops/s) | uncached (ops/s) | uncached ratio |
     |----|------|------------------:|---------------:|-------------:|------------------:|-----------------:|---------------:|
     | 0.001 | 0.10 | 69,051 | 68,593 | ~1.0x | 7,468 | 8,050 | ~1.0x |
     | 0.001 | 0.50 | 59,101 | 59,414 | ~1.0x | 20,071 | 19,317 | ~1.0x |
     | 0.005 | 0.10 | 15,981 | 15,956 | ~1.0x | 3,874 | 3,524 | ~1.0x |
     | 0.005 | 0.50 | 10,196 | 10,465 | ~1.0x | 4,738 | 4,435 | ~1.0x |
     | 0.01 | 0.10 | 6,036 | 10,938 | **1.81x** | 2,535 | 2,452 | ~1.0x |
     | 0.01 | 0.50 | 4,194 | 13,425 | **3.20x** | 2,888 | 2,879 | ~1.0x |
     | 0.02 | 0.10 | 2,735 | 8,361 | **3.06x** | 1,542 | 1,492 | ~1.0x |
     | 0.02 | 0.50 | 1,994 | 9,600 | **4.81x** | 1,578 | 1,569 | ~1.0x |
     | 0.03 | 0.10 | 1,812 | 6,622 | **3.65x** | 1,114 | 1,151 | ~1.0x |
     | 0.03 | 0.50 | 1,334 | 8,259 | **6.19x** | 1,097 | 1,101 | ~1.0x |
     | 0.10 | 0.10 | 546 | 3,464 | **6.35x** | 447 | 2,010 | **4.50x** |
     | 0.10 | 0.50 | 422 | 3,427 | **8.12x** | 375 | 2,490 | **6.64x** |
     | 0.50 | 0.10 | 382 | 4,847 | **12.68x** | 380 | 2,293 | **6.03x** |
     | 0.50 | 0.50 | 79 | 4,889 | **61.91x** | 85 | 3,281 | **38.53x** |


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "michaeljmarshall (via GitHub)" <gi...@apache.org>.
michaeljmarshall commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r4138760041


##########
lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java:
##########
@@ -262,13 +264,57 @@ assert assertItersOnSameDoc()
       return doNext(lead.advance(target));
     }
 
+    @Override
+    public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
+      assert offset <= docID() : "offset=" + offset + " docID()=" + docID() + " upTo=" + upTo;
+      int doc = docID();
+      if (doc >= upTo) {
+        return;
+      }
+
+      // Bulk masking has fixed per-window cost; sparse leads are cheaper to advance per doc.
+      if (lead.cost() < bitSet.length()) {
+        super.intoBitSet(upTo, bitSet, offset);
+        return;
+      }
+
+      int bulkUpTo = Math.min(upTo, minLength);
+      long destinationEnd = (long) offset + bitSet.length();
+      if (destinationEnd < bulkUpTo) {
+        bulkUpTo = (int) destinationEnd;
+      }
+
+      if (doc < bulkUpTo) {
+        if (scratch == null || scratch.length() != bitSet.length()) {
+          scratch = new FixedBitSet(bitSet.length());
+        } else {
+          scratch.clear();
+        }
+
+        lead.intoBitSet(bulkUpTo, scratch, offset);
+        for (BitSet bitSetMask : bitSets) {
+          bitSetMask.applyMask(scratch, offset);
+        }
+        bitSet.or(scratch);
+
+        doNext(lead.docID());
+      }
+
+      if (docID() < upTo) {
+        super.intoBitSet(upTo, bitSet, offset);
+      }
+    }
+
     private int doNext(int doc) throws IOException {
       advanceLead:
       for (; ; doc = lead.nextDoc()) {
         if (doc >= minLength) {
           if (doc != NO_MORE_DOCS) {
             lead.advance(NO_MORE_DOCS);
           }
+          for (BitSetIterator iterator : bitSetIterators) {
+            iterator.setDocId(NO_MORE_DOCS);
+          }

Review Comment:
   Not sure if it is worth back porting to older branches, but it is something that we've hit https://github.com/elastic/elasticsearch/pull/160540#pullrequestreview-5358742778. However, it would seem that this is only reachable when the iterator has returned `NO_MORE_DOCS`, and the javadoc specifically says:
   
   ```
    * This abstract class defines methods to iterate over a set of non-decreasing doc ids. Note that
    * this class assumes it iterates on doc Ids, and therefore {@link #NO_MORE_DOCS} is set to {@value
    * #NO_MORE_DOCS} in order to be used as a sentinel object. Implementations of this class are
    * expected to consider {@link Integer#MAX_VALUE} as an invalid value.
    ```



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on code in PR #16146:
URL: https://github.com/apache/lucene/pull/16146#discussion_r3341297995


##########
lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java:
##########
@@ -62,6 +62,10 @@ public float score() throws IOException {
     return (float) sum;
   }
 
+  boolean canBulkCollectDocIdStream() {

Review Comment:
   This is unused now I think?



##########
lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java:
##########
@@ -145,6 +146,10 @@ static DocIdSetIterator createConjunction(
     return disi;
   }
 
+  static boolean canBulkIntoBitSet(DocIdSetIterator iterator) {

Review Comment:
   I think we can remove this now, as it's just used for testing and we have other ways of checking which paths are being used.



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4616765668

   @romseygeek @jimczi Now that `ConstantScoreBulkScorer` can confirm a `TwoPhaseIterator` directly, I dropped the `twoPhase == null` gate in `filteredOptionalBulkScorer()`. 
   Two-phase optional clauses (e.g. phrase queries) now also go through the windowed `ConstantScoreBulkScorer` path instead of falling back to `DefaultBulkScorer`.


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "costin (via GitHub)" <gi...@apache.org>.
costin commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4711365976

   @romseygeek done, thanks for the ping!


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Optimize cached-filter conjunction batching [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on PR #16146:
URL: https://github.com/apache/lucene/pull/16146#issuecomment-4590769936

   Shouldn't the query cache be going through ConstantScoreScorerSupplier/ConstantScoreBulkScorer now?


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org