Skip to content

Commit

Permalink
LUCENE-8602: Share TermsEnum if possible while applying DV updates
Browse files Browse the repository at this point in the history
Today we pull a new terms enum when we apply DV updates even though the
field stays the same which is the common case. Benchmarking this on a
larger term dictionary with a significant number of updates shows a
2x improvement in performance.
  • Loading branch information
s1monw committed Dec 11, 2018
1 parent 3147c13 commit d08e2d4
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private static long applyDocValuesUpdates(BufferedUpdatesStream.SegmentState seg
long delGen,
boolean segmentPrivateDeletes) throws IOException {

TermsEnum termsEnum;
TermsEnum termsEnum = null;
PostingsEnum postingsEnum = null;

// TODO: we can process the updates per DV field, from last to first so that
Expand All @@ -492,11 +492,14 @@ private static long applyDocValuesUpdates(BufferedUpdatesStream.SegmentState seg
boolean isNumeric = value.isNumeric();
FieldUpdatesBuffer.BufferedUpdateIterator iterator = value.iterator();
FieldUpdatesBuffer.BufferedUpdate bufferedUpdate;
String previousField = null;
while ((bufferedUpdate = iterator.next()) != null) {
Terms terms = segState.reader.terms(bufferedUpdate.termField);
if (terms != null) {
termsEnum = terms.iterator();
} else {
if (previousField == null || previousField.equals(bufferedUpdate.termField) == false) {
previousField = bufferedUpdate.termField;
Terms terms = segState.reader.terms(previousField);
termsEnum = terms == null ? null : terms.iterator();
}
if (termsEnum == null) {
// no terms in this segment for this field
continue;
}
Expand Down

0 comments on commit d08e2d4

Please sign in to comment.