From 5bca3d196096866a8c9e73d619bee656594bb895 Mon Sep 17 00:00:00 2001 From: zacharymorn Date: Thu, 25 Feb 2021 18:32:34 -0800 Subject: [PATCH] LUCENE-9639: Implements SimpleTextVectorReader#ramBytesUsed (#2433) * Use single class imports --- .../simpletext/SimpleTextVectorReader.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextVectorReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextVectorReader.java index 15603c140c5..1ef02007552 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextVectorReader.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextVectorReader.java @@ -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