Apache Lucene open-source search software
LUCENE-10555: avoid NumericLeafComparator#iteratorCost repeated initialization when NumericLeafComparator#setScorer is called (#864)
xiaopingf431511cb712
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 1c6f87b6d89..48bd2d12c8f 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -118,6 +118,9 @@ ImprovementsOptimizations---------------------+* LUCENE-10555: avoid NumericLeafComparator#iteratorCost repeated initialization+ when NumericLeafComparator#setScorer is called. (Jianping Weng)+* LUCENE-10452: Hunspell: call checkCanceled less frequently to reduce the overhead (Peter Gromov)* LUCENE-10451: Hunspell: don't perform potentially expensive spellchecking after timeout (Peter Gromov)diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.javaindex a44583fceba..ddbf9a1d4ad 100644--- a/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java+++ b/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java@@ -91,7 +91,7 @@ public abstract class NumericComparator<T extends Number> extends FieldComparatoprivate final byte[] maxValueAsBytes;private DocIdSetIterator competitiveIterator;- private long iteratorCost;+ private long iteratorCost = -1;private int maxDocVisited = -1;private int updateCounter = 0;@@ -165,7 +165,7 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato@Overridepublic void setScorer(Scorable scorer) throws IOException {- if (scorer instanceof Scorer) {+ if (iteratorCost == -1 && scorer instanceof Scorer) {iteratorCost =((Scorer) scorer).iterator().cost(); // starting iterator cost is the scorer's costupdateCompetitiveIterator(); // update an iterator when we have a new segment