Apache Lucene open-source search software
Skip runs of excluded docs in ReqExclBulkScorer for two-phase clauses (#16307)
Jim Ferenczi446dda966920
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 5d530c76bb0..d51fb3955fa 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -149,6 +149,10 @@ ImprovementsOptimizations---------------------+* GITHUB#16307: ReqExclBulkScorer now skips runs of excluded docs via+ TwoPhaseIterator#docIDRunEnd for two-phase excluded clauses (e.g. a doc-values+ not-equals filter), instead of advancing one doc at a time. (Jim Ferenczi)+* GITHUB#16254: Enable the vectorized findNextGEQ path on aarch64, where it was disabled on coreswith fewer than 8 int lanes (Graviton2 and Graviton4). The vector compare beats the scalarfallback by +75% on Graviton4 and +35% on Graviton2 (AdvanceBenchmark). (Shitij Bhargava)diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqExclBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqExclBulkScorer.javaindex da665c0dd95..42f7110cd8e 100644--- a/lucene/core/src/java/org/apache/lucene/search/ReqExclBulkScorer.java+++ b/lucene/core/src/java/org/apache/lucene/search/ReqExclBulkScorer.java@@ -61,8 +61,10 @@ final class ReqExclBulkScorer extends BulkScorer {// from upTo to docIdRunEnd() are excluded, so we scored up to docIdRunEnd()upTo = Math.min(exclApproximation.docIDRunEnd(), max);} else if (exclTwoPhase.matches()) {- // upTo is excluded so we can consider that we scored up to upTo+1- upTo += 1;+ // upTo is excluded; skip the whole run of consecutive excluded docs at once, like the+ // non-two-phase branch above. Clamp to at least upTo+1 to guarantee progress in case a+ // TwoPhaseIterator returns a run end that does not move past the current doc.+ upTo = Math.max(upTo + 1, Math.min(exclTwoPhase.docIDRunEnd(), max));}exclDoc = exclApproximation.nextDoc();} else {diff --git a/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java b/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.javaindex f4b7410ec9f..8a83e865480 100644--- a/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java+++ b/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java@@ -117,10 +117,11 @@ public abstract class TwoPhaseIterator {* <p><b>Note</b>: It is illegal to call this method when the approximation is exhausted or not* positioned.*- * <p>The default implementation returns the current doc ID of the approximation.+ * <p>The default implementation assumes runs of a single doc ID and returns the current doc ID of+ * the approximation plus one, mirroring {@link DocIdSetIterator#docIDRunEnd()}.*/public int docIDRunEnd() throws IOException {- return approximation().docID();+ return approximation().docID() + 1;}/**