You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2022/05/10 11:07:49 UTC
[lucene] branch main updated: LUCENE-10555: avoid NumericLeafComparator#iteratorCost repeated initialization when NumericLeafComparator#setScorer is called (#864)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new f431511cb71 LUCENE-10555: avoid NumericLeafComparator#iteratorCost repeated initialization when NumericLeafComparator#setScorer is called (#864)
f431511cb71 is described below
commit f431511cb7128d1ff706b3072c619b6dd8c1e91f
Author: xiaoping <wj...@gmail.com>
AuthorDate: Tue May 10 19:07:41 2022 +0800
LUCENE-10555: avoid NumericLeafComparator#iteratorCost repeated initialization when NumericLeafComparator#setScorer is called (#864)
---
lucene/CHANGES.txt | 3 +++
.../java/org/apache/lucene/search/comparators/NumericComparator.java | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 1c6f87b6d89..48bd2d12c8f 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -118,6 +118,9 @@ Improvements
Optimizations
---------------------
+* 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.java
index 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 FieldComparato
private 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
@Override
public 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 cost
updateCompetitiveIterator(); // update an iterator when we have a new segment