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/08/28 11:09:07 UTC
(lucene) branch branch_10x updated: PostingsDecodingUtil: interchange loops to enable better memory access and SIMD vectorisation (#15110)
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 de669618c3c PostingsDecodingUtil: interchange loops to enable better memory access and SIMD vectorisation (#15110)
de669618c3c is described below
commit de669618c3c07a47633f1f3cefcd852ced246eee
Author: Ramakrishna Chilaka <49...@users.noreply.github.com>
AuthorDate: Thu Aug 28 16:34:49 2025 +0530
PostingsDecodingUtil: interchange loops to enable better memory access and SIMD vectorisation (#15110)
---
lucene/CHANGES.txt | 2 ++
.../benchmark/jmh/PostingIndexInputBenchmark.java | 16 ++++++++++++++++
.../internal/vectorization/PostingDecodingUtil.java | 19 +++++++++++++------
3 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index dd72e6a39e6..84dd7462113 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -48,6 +48,8 @@ New Features
* GITHUB#14729: Support for Re-Ranking Queries using Late Interaction Model Multi-Vectors. (Vigya Sharma, Jim Ferenczi)
+* GITHUB#15110: PostingsDecodingUtil: interchange loops to enable better memory access and SIMD vectorisation. (Ramakrishna Chilaka)
+
Improvements
---------------------
* GITHUB#14458: Add an IndexDeletion policy that retains the last N commits. (Owais Kazi)
diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/PostingIndexInputBenchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/PostingIndexInputBenchmark.java
index 0881d0f6bf9..c72809da847 100644
--- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/PostingIndexInputBenchmark.java
+++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/PostingIndexInputBenchmark.java
@@ -105,4 +105,20 @@ public class PostingIndexInputBenchmark {
postingIn.decodeAndPrefixSum(bpv, 100, values);
bh.consume(values);
}
+
+ @Benchmark
+ @Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
+ public void decodeVector(Blackhole bh) throws IOException {
+ in.seek(3); // random unaligned offset
+ postingIn.decode(bpv, values);
+ bh.consume(values);
+ }
+
+ @Benchmark
+ @Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
+ public void decodeAndPrefixSumVector(Blackhole bh) throws IOException {
+ in.seek(3); // random unaligned offset
+ postingIn.decodeAndPrefixSum(bpv, 100, values);
+ bh.consume(values);
+ }
}
diff --git a/lucene/core/src/java/org/apache/lucene/internal/vectorization/PostingDecodingUtil.java b/lucene/core/src/java/org/apache/lucene/internal/vectorization/PostingDecodingUtil.java
index e45ce55bbc5..b66600eee35 100644
--- a/lucene/core/src/java/org/apache/lucene/internal/vectorization/PostingDecodingUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/internal/vectorization/PostingDecodingUtil.java
@@ -44,14 +44,21 @@ public class PostingDecodingUtil {
public void splitInts(
int count, int[] b, int bShift, int dec, int bMask, int[] c, int cIndex, int cMask)
throws IOException {
- // Default implementation, which takes advantage of the C2 compiler's loop unrolling and
- // auto-vectorization.
in.readInts(c, cIndex, count);
- int maxIter = (bShift - 1) / dec;
- for (int i = 0; i < count; ++i) {
- for (int j = 0; j <= maxIter; ++j) {
- b[count * j + i] = (c[cIndex + i] >>> (bShift - j * dec)) & bMask;
+ final int maxIter = (bShift - 1) / dec;
+
+ // Process each shift level across all elements (better for vectorization)
+ for (int j = 0; j <= maxIter; ++j) {
+ final int shift = bShift - j * dec;
+ final int bOffset = count * j;
+ // Vectorizable loop: contiguous memory access with simple operations
+ for (int i = 0; i < count; ++i) {
+ b[bOffset + i] = (c[cIndex + i] >>> shift) & bMask;
}
+ }
+
+ // Apply mask to c array (vectorizable)
+ for (int i = 0; i < count; ++i) {
c[cIndex + i] &= cMask;
}
}