You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by be...@apache.org on 2025/10/21 11:09:45 UTC

(lucene) branch branch_10x updated: Use cached cardinality for AcceptDocs cost (#15343)

This is an automated email from the ASF dual-hosted git repository.

benwtrent 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 3eea6aa25ad Use cached cardinality for AcceptDocs cost (#15343)
3eea6aa25ad is described below

commit 3eea6aa25adb9950ec772f7e031bb891ed3481e3
Author: Benjamin Trent <be...@gmail.com>
AuthorDate: Tue Oct 21 06:57:24 2025 -0400

    Use cached cardinality for AcceptDocs cost (#15343)
    
    * Use cached cardinality for AcceptDocs cost
    
    * adding changes
---
 lucene/CHANGES.txt                                            | 3 +++
 lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3e4cb16919d..5935e840132 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -72,6 +72,9 @@ Optimizations
 
 * GITHUB#15261: Implement longValues for MultiFieldNormValues to speedup CombinedQuery (Ge Song)
 
+* GITHUB#15343: Ensure that `AcceptDocs#cost()` only ever calls `BitSets#cardinality()`
+  once per instance to avoid redundant computation. (Ben Trent)
+
 Bug Fixes
 ---------------------
 * GITHUB#14161: PointInSetQuery's constructor now throws IllegalArgumentException
diff --git a/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java b/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
index 175078434ef..8771f63438e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
+++ b/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
@@ -190,7 +190,7 @@ public abstract class AcceptDocs {
     @Override
     public int cost() throws IOException {
       createBitSetAcceptDocsIfNecessary();
-      return acceptBitSet.cardinality();
+      return cardinality;
     }
 
     @Override