Reuse Impacts instances across invocations. (#13878)

Our `ImpactsEnum` currently return a new object on every call to
`getImpacts()`, which shows up in nightly profiles.
This commit is contained in:
Adrien Grand 2024-10-09 14:37:20 +02:00
parent fb3065b4a6
commit dfa77b931c
1 changed files with 121 additions and 109 deletions

View File

@ -67,6 +67,12 @@ import org.apache.lucene.util.IOUtils;
public final class Lucene912PostingsReader extends PostingsReaderBase {
static final VectorizationProvider VECTORIZATION_PROVIDER = VectorizationProvider.getInstance();
// Dummy impacts, composed of the maximum possible term frequency and the lowest possible
// (unsigned) norm value. This is typically used on tail blocks, which don't actually record
// impacts as the storage overhead would not be worth any query evaluation speedup, since there's
// less than 128 docs left to evaluate anyway.
private static final List<Impact> DUMMY_IMPACTS =
Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));
private final IndexInput docIn;
private final IndexInput posIn;
@ -1221,8 +1227,6 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
// true if we shallow-advanced to a new block that we have not decoded yet
private boolean needsRefilling;
private final ByteArrayDataInput scratch = new ByteArrayDataInput();
// level 0 skip data
private int level0LastDocID;
private long level0DocEndFP;
@ -1470,9 +1474,10 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
return doc;
}
@Override
public Impacts getImpacts() {
return new Impacts() {
private final Impacts impacts =
new Impacts() {
private final ByteArrayDataInput scratch = new ByteArrayDataInput();
@Override
public int numLevels() {
@ -1521,9 +1526,13 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
return level1Impacts;
}
return Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));
return DUMMY_IMPACTS;
}
};
@Override
public Impacts getImpacts() {
return impacts;
}
@Override
@ -1575,8 +1584,6 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
// true if we shallow-advanced to a new block that we have not decoded yet
private boolean needsRefilling;
private final ByteArrayDataInput scratch = new ByteArrayDataInput();
// level 0 skip data
private int level0LastDocID;
private long level0DocEndFP;
@ -1801,9 +1808,10 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
}
}
@Override
public Impacts getImpacts() {
return new Impacts() {
private final Impacts impacts =
new Impacts() {
private final ByteArrayDataInput scratch = new ByteArrayDataInput();
@Override
public int numLevels() {
@ -1853,9 +1861,13 @@ public final class Lucene912PostingsReader extends PostingsReaderBase {
return level1Impacts;
}
return Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));
return DUMMY_IMPACTS;
}
};
@Override
public Impacts getImpacts() {
return impacts;
}
@Override