Browse Source

Optimize TSDBDocValuesFormat's prefix sum a bit. (#134204)

Benchmarks at https://github.com/apache/lucene/pull/14979 suggested that
tracking the sum in a variable performs faster than adding the previous value
to each array element.
Adrien Grand 1 month ago
parent
commit
34fd42d818

+ 4 - 2
server/src/main/java/org/elasticsearch/index/codec/tsdb/TSDBDocValuesEncoder.java

@@ -346,8 +346,10 @@ public final class TSDBDocValuesEncoder {
     }
 
     private void deltaDecode(long[] arr) {
-        for (int i = 1; i < numericBlockSize; ++i) {
-            arr[i] += arr[i - 1];
+        long sum = 0;
+        for (int i = 0; i < numericBlockSize; ++i) {
+            sum += arr[i];
+            arr[i] = sum;
         }
     }
 }