LUCENE-9639: Implements SimpleTextVectorReader#ramBytesUsed (#2433)

* Use single class imports
This commit is contained in:
zacharymorn 2021-02-25 18:32:34 -08:00 committed by GitHub
parent 62971c4f99
commit 5bca3d1960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -40,6 +40,7 @@ import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.StringHelper;
/**
@ -49,6 +50,10 @@ import org.apache.lucene.util.StringHelper;
* @lucene.experimental
*/
public class SimpleTextVectorReader extends VectorReader {
// shallowSizeOfInstance for fieldEntries map is included in ramBytesUsed() calculation
private static final long BASE_RAM_BYTES_USED =
RamUsageEstimator.shallowSizeOfInstance(SimpleTextVectorReader.class)
+ RamUsageEstimator.shallowSizeOfInstance(BytesRef.class);
private static final BytesRef EMPTY = new BytesRef("");
@ -174,7 +179,16 @@ public class SimpleTextVectorReader extends VectorReader {
@Override
public long ramBytesUsed() {
return 0;
// mirror implementation of Lucene90VectorReader#ramBytesUsed
long totalBytes = BASE_RAM_BYTES_USED;
totalBytes += RamUsageEstimator.sizeOf(scratch.bytes());
totalBytes +=
RamUsageEstimator.sizeOfMap(
fieldEntries, RamUsageEstimator.shallowSizeOfInstance(FieldEntry.class));
for (FieldEntry entry : fieldEntries.values()) {
totalBytes += RamUsageEstimator.sizeOf(entry.ordToDoc);
}
return totalBytes;
}
@Override