You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2024/10/08 17:00:29 UTC
(lucene) branch main updated: Speedup OrderedIntervalsSource (#13871)
This is an automated email from the ASF dual-hosted git repository.
abr 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 a14f9cd2eb2 Speedup OrderedIntervalsSource (#13871)
a14f9cd2eb2 is described below
commit a14f9cd2eb210499952fb4c5c739e63dcc56da85
Author: Armin Braun <me...@obrown.io>
AuthorDate: Tue Oct 8 19:00:24 2024 +0200
Speedup OrderedIntervalsSource (#13871)
Looking up the same indices out of a list is very costly, also better
keep things in local variables (likely registers) where possible.
---
.../queries/intervals/OrderedIntervalsSource.java | 42 +++++++++++++++-------
1 file changed, 29 insertions(+), 13 deletions(-)
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/intervals/OrderedIntervalsSource.java b/lucene/queries/src/java/org/apache/lucene/queries/intervals/OrderedIntervalsSource.java
index a89df974b66..c855d61d051 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/intervals/OrderedIntervalsSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/intervals/OrderedIntervalsSource.java
@@ -124,38 +124,54 @@ class OrderedIntervalsSource extends MinimizingConjunctionIntervalsSource {
start = end = slop = IntervalIterator.NO_MORE_INTERVALS;
int lastStart = Integer.MAX_VALUE;
boolean minimizing = false;
+ final var subIterators = this.subIterators;
+ int currentIndex = i;
while (true) {
while (true) {
- if (subIterators.get(i - 1).end() >= lastStart) {
+ var prev = subIterators.get(currentIndex - 1);
+ if (prev.end() >= lastStart) {
+ i = currentIndex;
return start;
}
- if (i == subIterators.size()
- || (minimizing && subIterators.get(i).start() > subIterators.get(i - 1).end())) {
+ if (currentIndex == subIterators.size()) {
+ break;
+ }
+ final IntervalIterator current = subIterators.get(currentIndex);
+ if (minimizing && (current.start() > prev.end())) {
break;
}
do {
- if (subIterators.get(i).end() >= lastStart
- || subIterators.get(i).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
+ if (current.end() >= lastStart
+ || current.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
+ i = currentIndex;
return start;
}
- } while (subIterators.get(i).start() <= subIterators.get(i - 1).end());
- i++;
+ } while (current.start() <= prev.end());
+ currentIndex++;
}
- start = subIterators.get(0).start();
+ var first = subIterators.getFirst();
+ final int start = first.start();
+ this.start = start;
if (start == NO_MORE_INTERVALS) {
+ i = currentIndex;
return end = NO_MORE_INTERVALS;
}
- end = subIterators.get(subIterators.size() - 1).end();
- slop = end - start + 1;
+ var last = subIterators.getLast();
+
+ final int end = last.end();
+ this.end = end;
+ int slop = end - start + 1;
for (IntervalIterator subIterator : subIterators) {
slop -= subIterator.width();
}
+ this.slop = slop;
onMatch.onMatch();
- lastStart = subIterators.get(subIterators.size() - 1).start();
- i = 1;
- if (subIterators.get(0).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
+ currentIndex = 1;
+ if (first.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
+ i = currentIndex;
return start;
}
+ lastStart = last.start();
minimizing = true;
}
}