You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by zh...@apache.org on 2024/10/08 02:30:10 UTC
(lucene) branch branch_10x updated: Reduce long[] array allocation for bitset in readBitSetIterator (#13828)
This is an automated email from the ASF dual-hosted git repository.
zhangchao 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 e10e9d136d7 Reduce long[] array allocation for bitset in readBitSetIterator (#13828)
e10e9d136d7 is described below
commit e10e9d136d7ee6959267044e1bea055b9907aee2
Author: Zhang Chao <80...@qq.com>
AuthorDate: Tue Oct 8 10:19:28 2024 +0800
Reduce long[] array allocation for bitset in readBitSetIterator (#13828)
---
lucene/CHANGES.txt | 2 +-
.../org/apache/lucene/util/bkd/DocIdsWriter.java | 22 +++++++++++++++-------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 98854bf8758..694143586d3 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -19,7 +19,7 @@ Improvements
Optimizations
---------------------
-(No changes)
+* GITHUB#13828: Reduce long[] array allocation for bitset in readBitSetIterator. (Zhang Chao)
Bug Fixes
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
index 9f6a10b9ddc..b9ea0d9aa08 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
@@ -17,13 +17,16 @@
package org.apache.lucene.util.bkd;
import java.io.IOException;
+import java.util.Arrays;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.DocBaseBitSetIterator;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.LongsRef;
final class DocIdsWriter {
@@ -36,6 +39,7 @@ final class DocIdsWriter {
private static final byte LEGACY_DELTA_VINT = (byte) 0;
private final int[] scratch;
+ private final LongsRef scratchLongs = new LongsRef();
/**
* IntsRef to be used to iterate over the scratch buffer. A single instance is reused to avoid
@@ -205,12 +209,17 @@ final class DocIdsWriter {
}
}
- private static DocIdSetIterator readBitSetIterator(IndexInput in, int count) throws IOException {
+ private DocIdSetIterator readBitSetIterator(IndexInput in, int count) throws IOException {
int offsetWords = in.readVInt();
int longLen = in.readVInt();
- long[] bits = new long[longLen];
- in.readLongs(bits, 0, longLen);
- FixedBitSet bitSet = new FixedBitSet(bits, longLen << 6);
+ scratchLongs.longs = ArrayUtil.growNoCopy(scratchLongs.longs, longLen);
+ in.readLongs(scratchLongs.longs, 0, longLen);
+ // make ghost bits clear for FixedBitSet.
+ if (longLen < scratchLongs.length) {
+ Arrays.fill(scratchLongs.longs, longLen, scratchLongs.longs.length, 0);
+ }
+ scratchLongs.length = longLen;
+ FixedBitSet bitSet = new FixedBitSet(scratchLongs.longs, longLen << 6);
return new DocBaseBitSetIterator(bitSet, count, offsetWords << 6);
}
@@ -230,7 +239,7 @@ final class DocIdsWriter {
}
}
- private static void readBitSet(IndexInput in, int count, int[] docIDs) throws IOException {
+ private void readBitSet(IndexInput in, int count, int[] docIDs) throws IOException {
DocIdSetIterator iterator = readBitSetIterator(in, count);
int docId, pos = 0;
while ((docId = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
@@ -307,8 +316,7 @@ final class DocIdsWriter {
}
}
- private static void readBitSet(IndexInput in, int count, IntersectVisitor visitor)
- throws IOException {
+ private void readBitSet(IndexInput in, int count, IntersectVisitor visitor) throws IOException {
DocIdSetIterator bitSetIterator = readBitSetIterator(in, count);
visitor.visit(bitSetIterator);
}