Avoid double-counting Automaton in CompiledAutomaton.ramBytesUsed#16046
Open
reugn wants to merge 2 commits into
Open
Avoid double-counting Automaton in CompiledAutomaton.ramBytesUsed#16046reugn wants to merge 2 commits into
reugn wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CompiledAutomaton.ramBytesUsed()counts the underlying Automaton twice on the DFA path, over-reporting retained heap by 18–35% on non-trivial wildcard and regexp queries.The
automatonfield is aliased torunAutomaton.automaton— a single Automaton instance referenced from two places:ramBytesUsed()accounts for it twice: once directly viasizeOfObject(automaton), and again throughsizeOfObject(runAutomaton)which delegates toRunAutomaton.ramBytesUsed()and addssizeOfObject(automaton)itself.The fix is to drop the redundant
sizeOfObject(automaton)fromCompiledAutomaton.ramBytesUsed(). In the NFA branch both fields arenull, so this is a no-op there.Cross-checked against org.openjdk.jol.info.GraphLayout.parseInstance(ca).totalSize() — reported below is CompiledAutomaton.ramBytesUsed(), retained is JOL's GraphLayout.totalSize().
*foo**foo*bar*baz**a*b*c*d*e*f*g**+x×1000 +**+x×3000 +**a*b*…*j*(depth 10)*a*b*…*t*(depth 20).*foo.*bar.*After the fix, ramBytesUsed() lands within a fixed +159-byte offset of actual retained heap across all cases.