You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2025/09/10 19:48:19 UTC

(lucene) branch branch_10x updated: optimise prefix sums in Lucene104PostingsReader (#15175)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 621b86afed6 optimise prefix sums in Lucene104PostingsReader (#15175)
621b86afed6 is described below

commit 621b86afed6471733e5effc21960add6796b533c
Author: Ramakrishna Chilaka <49...@users.noreply.github.com>
AuthorDate: Thu Sep 11 01:16:05 2025 +0530

    optimise prefix sums in Lucene104PostingsReader (#15175)
---
 .../codecs/lucene104/Lucene104PostingsReader.java     | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsReader.java
index aa24c4292b2..ee028c4f847 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsReader.java
@@ -193,10 +193,11 @@ public final class Lucene104PostingsReader extends PostingsReaderBase {
     }
   }
 
-  static void prefixSum(int[] buffer, int count, long base) {
-    buffer[0] += base;
-    for (int i = 1; i < count; ++i) {
-      buffer[i] += buffer[i - 1];
+  static void prefixSum(int[] buffer, int count, int base) {
+    int sum = base;
+    for (int i = 0; i < count; ++i) {
+      sum += buffer[i];
+      buffer[i] = sum;
     }
   }
 
@@ -596,11 +597,7 @@ public final class Lucene104PostingsReader extends PostingsReaderBase {
       if (bitsPerValue > 0) {
         // block is encoded as 256 packed integers that record the delta between doc IDs
         forUtil.decode(bitsPerValue, docInUtil, docBuffer);
-        int sum = prevDocID;
-        for (int i = 0; i < BLOCK_SIZE; ++i) {
-          sum += docBuffer[i];
-          docBuffer[i] = sum;
-        }
+        prefixSum(docBuffer, BLOCK_SIZE, prevDocID);
         encoding = DeltaEncoding.PACKED;
       } else {
         // block is encoded as a bit set
@@ -622,9 +619,7 @@ public final class Lucene104PostingsReader extends PostingsReaderBase {
           for (int i = 0; i < numLongs - 1; ++i) {
             docCumulativeWordPopCounts[i] = Long.bitCount(docBitSet.getBits()[i]);
           }
-          for (int i = 1; i < numLongs - 1; ++i) {
-            docCumulativeWordPopCounts[i] += docCumulativeWordPopCounts[i - 1];
-          }
+          prefixSum(docCumulativeWordPopCounts, numLongs - 1, 0);
           docCumulativeWordPopCounts[numLongs - 1] = BLOCK_SIZE;
           assert docCumulativeWordPopCounts[numLongs - 2]
                   + Long.bitCount(docBitSet.getBits()[numLongs - 1])