Skip to content

Commit 1bd0234

Browse files
committed
Optimize TSDBDocValuesFormat's prefix sum a bit.
Benchmarks at apache/lucene#14979 suggested that tracking the sum in a variable performs faster than adding the previous value to each array element.
1 parent cc66490 commit 1bd0234

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/TSDBDocValuesEncoder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,10 @@ private void add(long[] arr, long min) {
346346
}
347347

348348
private void deltaDecode(long[] arr) {
349-
for (int i = 1; i < numericBlockSize; ++i) {
350-
arr[i] += arr[i - 1];
349+
long sum = 0;
350+
for (int i = 0; i < numericBlockSize; ++i) {
351+
sum += arr[i];
352+
arr[i] = sum;
351353
}
352354
}
353355
}

0 commit comments

Comments
 (0)