Lazy initialize ForDeltaUtil and ForUtil in Lucene912PostingsReader (#13885)

Lazy initialize these fields. They consume/cause a lot of memory/GC because they are
allocated frequently (~7% of all allocations in luceneutil's wikimedia medium run for me).
This does not cause any measurable slowdown as far as runtime is concerned and since these are not
even needed for all instances (in fact they are rarely used in the queries the benchmark explores)
save qutie a few CPU cycles for collecting and allocating them.
This commit is contained in:
Armin Braun 2024-10-12 12:42:29 +02:00
parent 8180f43678
commit a6a6519ee7
1 changed files with 14 additions and 4 deletions

View File

@ -346,8 +346,8 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
final class BlockDocsEnum extends PostingsEnum {
final ForDeltaUtil forDeltaUtil = new ForDeltaUtil();
final PForUtil pforUtil = new PForUtil(new ForUtil());
private ForDeltaUtil forDeltaUtil;
private PForUtil pforUtil;
private final long[] docBuffer = new long[BLOCK_SIZE + 1];
private final long[] freqBuffer = new long[BLOCK_SIZE];
@ -410,6 +410,10 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
public PostingsEnum reset(IntBlockTermState termState, int flags) throws IOException {
docFreq = termState.docFreq;
if (pforUtil == null && docFreq >= BLOCK_SIZE) {
pforUtil = new PForUtil(new ForUtil());
forDeltaUtil = new ForDeltaUtil();
}
totalTermFreq = indexHasFreq ? termState.totalTermFreq : docFreq;
singletonDocID = termState.singletonDocID;
if (docFreq > 1) {
@ -627,8 +631,8 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
final class EverythingEnum extends PostingsEnum {
final ForDeltaUtil forDeltaUtil = new ForDeltaUtil();
final PForUtil pforUtil = new PForUtil(new ForUtil());
private ForDeltaUtil forDeltaUtil;
private PForUtil pforUtil;
private final long[] docBuffer = new long[BLOCK_SIZE + 1];
private final long[] freqBuffer = new long[BLOCK_SIZE + 1];
@ -756,12 +760,18 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
public PostingsEnum reset(IntBlockTermState termState, int flags) throws IOException {
docFreq = termState.docFreq;
if (forDeltaUtil == null && docFreq >= BLOCK_SIZE) {
forDeltaUtil = new ForDeltaUtil();
}
// Where this term's postings start in the .pos file:
final long posTermStartFP = termState.posStartFP;
// Where this term's payloads/offsets start in the .pay
// file:
final long payTermStartFP = termState.payStartFP;
totalTermFreq = termState.totalTermFreq;
if (pforUtil == null && totalTermFreq >= BLOCK_SIZE) {
pforUtil = new PForUtil(new ForUtil());
}
singletonDocID = termState.singletonDocID;
if (docFreq > 1) {
if (docIn == null) {