Apache Lucene open-source search software
Avoid performance regression by constructing lazily the PointTree in NumericComparator (#13498) (#13877)
Ignacio Vera07955ff88d6e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2bfde84eabe..d547d7bdc65 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -333,6 +333,8 @@ Bug Fixes* GITHUB#12878: Fix the declared Exceptions of Expression#evaluate() to match thoseof DoubleValues#doubleValue(). (Uwe Schindler)+* GITHUB#13498: Avoid performance regression by constructing lazily the PointTree in NumericComparator, (Ignacio Vera)+Changes in Runtime Behavior---------------------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 31022f6bb05..2bd594cc731 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@@ -95,7 +95,8 @@ public abstract class NumericComparator<T extends Number> extends FieldComparatoprivate final LeafReaderContext context;protected final NumericDocValues docValues;private final PointValues pointValues;- private final PointValues.PointTree pointTree;+ // lazily constructed to avoid performance overhead when this is not used+ private PointValues.PointTree pointTree;// if skipping functionality should be enabled on this segmentprivate final boolean enableSkipping;private final int maxDoc;@@ -139,7 +140,6 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato+ " expected "+ bytesCount);}- this.pointTree = pointValues.getPointTree();this.enableSkipping = true; // skipping is enabled when points are availablethis.maxDoc = context.reader().maxDoc();this.competitiveIterator = DocIdSetIterator.all(maxDoc);@@ -147,7 +147,6 @@ public abstract class NumericComparator<T extends Number> extends FieldComparatoencodeTop();}} else {- this.pointTree = null;this.enableSkipping = false;this.maxDoc = 0;}@@ -273,7 +272,8 @@ public abstract class NumericComparator<T extends Number> extends FieldComparatofinal long threshold = iteratorCost >>> 3;- if (PointValues.isEstimatedPointCountGreaterThanOrEqualTo(visitor, pointTree, threshold)) {+ if (PointValues.isEstimatedPointCountGreaterThanOrEqualTo(+ visitor, getPointTree(), threshold)) {// the new range is not selective enough to be worth materializing, it doesn't reduce number// of docs at least 8xupdateSkipInterval(false);@@ -290,6 +290,13 @@ public abstract class NumericComparator<T extends Number> extends FieldComparatoupdateSkipInterval(true);}+ private PointValues.PointTree getPointTree() throws IOException {+ if (pointTree == null) {+ pointTree = pointValues.getPointTree();+ }+ return pointTree;+ }+private void updateSkipInterval(boolean success) {if (updateCounter > 256) {if (success) {