perf: defer SharedInfo allocation in ClassInfoCache.share()#68
Closed
perf: defer SharedInfo allocation in ClassInfoCache.share()#68
Conversation
Defer SharedInfo allocation until after slot search completes, avoiding an unnecessary allocation when the class name already exists in the cache. Also compare class names directly instead of via SharedInfo .equals(), which avoids an intermediate object creation. Note: find() is intentionally left using contentEquals(CharSequence) since callers may pass non-String CharSequence types (e.g. when matching against method signatures or field descriptors). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b8bddbb to
504a554
Compare
Contributor
Author
|
Closing — on closer inspection the allocation is deferred but not eliminated, so there's no meaningful performance improvement. The original code structure is clearer. |
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.
What Does This Do
Defer
SharedInfoallocation inClassInfoCache.share()until after the slot search completes. Also compare class names directly withclassName.equals()instead of viaSharedInfo.equals(), which avoids creating aSharedInfoobject just for the lookup.Motivation
The original code eagerly allocates a
SharedInfowrapper before searching for a slot:When the class name already exists in the cache (the update-existing-entry path in
share()), the allocation is done before the search even begins. Moving it after the search avoids the allocation overhead during the slot lookup, and comparingclassName.equals()directly is simpler than going throughSharedInfo.equals().Benchmark Notes
The existing
ClassInfoCacheBenchmarkexercisesfind()+share()in a loop, but after warmup all entries are cached sofind()always succeeds andshare()is never called on the hot path. This means theshare()optimization is not measurable with this benchmark.The improvement applies during cache population and when entries are being updated/evicted — not the steady-state lookup path that the benchmark measures.
Results are within noise for the steady-state path as expected. The allocation savings would be visible in a benchmark that continuously inserts new entries.
Additional Notes
share()is changed;find()is untouchedshare()parameter isString, soclassName.equals()is always validfind()with aString-specialized comparison, but this was dropped because callers may pass non-StringCharSequencetypes (e.g. matching against method signatures or field descriptors)Contributor Checklist
Jira ticket: N/A — performance optimization, no ticket
🤖 Generated with Claude Code