Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce FST block size for BlockTreeTermsWriter (#12604) #2677

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lucene/CHANGES.txt
Expand Up @@ -26,6 +26,11 @@ Bug Fixes
* GITHUB#12352: [Tessellator] Improve the checks that validate the diagonal between two polygon nodes so
the resulting polygons are valid counter clockwise polygons. (Ignacio Vera)

Optimizations
---------------------
* GITHUB#12604: Estimate the block size of FST BytesStore in BlockTreeTermsWriter
to reduce GC load during indexing. (Guo Feng)

======================= Lucene 8.11.2 =======================

Bug Fixes
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.apache.lucene.util.fst.BytesRefFSTEnum;
import org.apache.lucene.util.fst.FST;
import org.apache.lucene.util.fst.Util;
import org.apache.lucene.util.packed.PackedInts;

/*
TODO:
Expand Down Expand Up @@ -427,10 +428,22 @@ public void compileIndex(List<PendingBlock> blocks, RAMOutputStream scratchBytes
}
}

long estimateSize = prefix.length;
for (PendingBlock block : blocks) {
if (block.subIndices != null) {
for (FST<BytesRef> subIndex : block.subIndices) {
estimateSize += subIndex.numBytes();
}
}
}
int estimateBitsRequired = PackedInts.bitsRequired(estimateSize);
int pageBits = Math.min(15, Math.max(6, estimateBitsRequired));


final ByteSequenceOutputs outputs = ByteSequenceOutputs.getSingleton();
final Builder<BytesRef> indexBuilder = new Builder<>(FST.INPUT_TYPE.BYTE1,
0, 0, true, false, Integer.MAX_VALUE,
outputs, true, 15);
outputs, true, pageBits);
//if (DEBUG) {
// System.out.println(" compile index for prefix=" + prefix);
//}
Expand Down
4 changes: 4 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/fst/FST.java
Expand Up @@ -489,6 +489,10 @@ void finish(long newStartNode) throws IOException {
startNode = newStartNode;
bytes.finish();
}

public long numBytes() {
return bytes.getPosition();
}

public T getEmptyOutput() {
return emptyOutput;
Expand Down