Skip to content

Apache Lucene open-source search software

Reduce the heap use of BKDReader instances (#13464)

Armin Braunc7a7d48d657f
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java
index d2d326b3a15..b2b109769f5 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDReader.java
@@ -43,7 +43,9 @@ public class BKDReader extends PointValues {
final int version;
final long minLeafBlockFP;
- final IndexInput packedIndex;
+ private final long indexStartPointer;
+ private final int numIndexBytes;
+ private final IndexInput indexIn;
// if true, the tree is a legacy balanced tree
private final boolean isTreeBalanced;
@@ -95,8 +97,7 @@ public class BKDReader extends PointValues {
pointCount = metaIn.readVLong();
docCount = metaIn.readVInt();
- int numIndexBytes = metaIn.readVInt();
- long indexStartPointer;
+ numIndexBytes = metaIn.readVInt();
if (version >= BKDWriter.VERSION_META_FILE) {
minLeafBlockFP = metaIn.readLong();
indexStartPointer = metaIn.readLong();
@@ -105,7 +106,7 @@ public class BKDReader extends PointValues {
minLeafBlockFP = indexIn.readVLong();
indexIn.seek(indexStartPointer);
}
- this.packedIndex = indexIn.slice("packedIndex", indexStartPointer, numIndexBytes);
+ this.indexIn = indexIn;
this.in = dataIn;
// for only one leaf, balanced and unbalanced trees can be handled the same way
// we set it to unbalanced.
@@ -158,7 +159,7 @@ public class BKDReader extends PointValues {
@Override
public PointTree getPointTree() throws IOException {
return new BKDPointTree(
- packedIndex.clone(),
+ indexIn.slice("packedIndex", indexStartPointer, numIndexBytes),
this.in.clone(),
config,
numLeaves,