Skip to content

Commit 5595723

Browse files
reugnjavanna
authored andcommitted
Avoid double-counting Automaton in CompiledAutomaton.ramBytesUsed (#16046)
1 parent 4c71597 commit 5595723

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ Bug Fixes
234234

235235
* GITHUB#15878: Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly (Binlong Gao)
236236

237+
* GITHUB#16046: Fix double-counting of underlying Automaton in CompiledAutomaton#ramBytesUsed. (Eugene Rizhkov)
238+
237239
Other
238240
---------------------
239241
* GITHUB#15586: Document that scoring and ranking may change across major Lucene versions, and that applications requiring stable ranking should explicitly configure Similarity. (Parveen Saini)

lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ public boolean equals(Object obj) {
535535

536536
@Override
537537
public long ramBytesUsed() {
538+
// this.automaton is accounted via runAutomaton.ramBytesUsed()
538539
return BASE_RAM_BYTES
539-
+ RamUsageEstimator.sizeOfObject(automaton)
540540
+ RamUsageEstimator.sizeOfObject(commonSuffixRef)
541541
+ RamUsageEstimator.sizeOfObject(runAutomaton)
542542
+ RamUsageEstimator.sizeOfObject(nfaRunAutomaton)

lucene/core/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.Set;
2525
import org.apache.lucene.tests.util.LuceneTestCase;
26+
import org.apache.lucene.tests.util.RamUsageTester;
2627
import org.apache.lucene.tests.util.TestUtil;
2728
import org.apache.lucene.util.BytesRef;
2829
import org.apache.lucene.util.BytesRefBuilder;
@@ -160,4 +161,16 @@ public void testUnicodeSingleton() throws Exception {
160161
CompiledAutomaton ca = new CompiledAutomaton(a, true, true, false);
161162
assertEquals(CompiledAutomaton.AUTOMATON_TYPE.SINGLE, ca.type);
162163
}
164+
165+
public void testRamBytesUsed() {
166+
Automaton a =
167+
Operations.determinize(new RegExp(".*foo.*bar.*baz.*").toAutomaton(), Integer.MAX_VALUE);
168+
CompiledAutomaton ca = new CompiledAutomaton(a, false, true, false);
169+
assertEquals(CompiledAutomaton.AUTOMATON_TYPE.NORMAL, ca.type);
170+
assertNotNull(ca.runAutomaton);
171+
172+
long reported = ca.ramBytesUsed();
173+
long actual = RamUsageTester.ramUsed(ca);
174+
assertEquals((double) actual, (double) reported, (double) actual * 0.10);
175+
}
163176
}

0 commit comments

Comments
 (0)