Skip to content

Commit

Permalink
Avoid performance regression by constructing lazily the PointTree in …
Browse files Browse the repository at this point in the history
…NumericComparator (#13498) (#13877)
  • Loading branch information
iverase authored and javanna committed Nov 5, 2024
1 parent e37eaea commit 07955ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ Bug Fixes
* GITHUB#12878: Fix the declared Exceptions of Expression#evaluate() to match those
of DoubleValues#doubleValue(). (Uwe Schindler)

* GITHUB#13498: Avoid performance regression by constructing lazily the PointTree in NumericComparator, (Ignacio Vera)

Changes in Runtime Behavior
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public abstract class NumericLeafComparator implements LeafFieldComparator {
private 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 segment
private final boolean enableSkipping;
private final int maxDoc;
Expand Down Expand Up @@ -139,15 +140,13 @@ public NumericLeafComparator(LeafReaderContext context) throws IOException {
+ " expected "
+ bytesCount);
}
this.pointTree = pointValues.getPointTree();
this.enableSkipping = true; // skipping is enabled when points are available
this.maxDoc = context.reader().maxDoc();
this.competitiveIterator = DocIdSetIterator.all(maxDoc);
if (leafTopSet) {
encodeTop();
}
} else {
this.pointTree = null;
this.enableSkipping = false;
this.maxDoc = 0;
}
Expand Down Expand Up @@ -273,7 +272,8 @@ public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue

final 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 8x
updateSkipInterval(false);
Expand All @@ -290,6 +290,13 @@ public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue
updateSkipInterval(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) {
Expand Down

0 comments on commit 07955ff

Please sign in to comment.