perf(core): [Init Reflection 2] Cache class lookups and collapse double probes#5636
Open
runningcode wants to merge 3 commits into
Open
perf(core): [Init Reflection 2] Cache class lookups and collapse double probes#5636runningcode wants to merge 3 commits into
runningcode wants to merge 3 commits into
Conversation
Class availability is fixed for the lifetime of the process, so cache LoadClass results to avoid repeated Class.forName lookups (and the exceptions thrown for absent classes) when the same class is probed more than once. Also collapse the isClassAvailable-then-loadClass double probe in the OpenTelemetry span/scopes factories into a single loadClass call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
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.
PR Stack (Init Reflection)
Part of JAVA-587
📜 Description
Two related reflection-cost reductions on top of [Init Reflection 1]:
LoadClassresults. Whether a class is on the classpath doesn't change during the process lifetime, so results (including "not available") are cached in a static map. Repeated probes of the same class skipClass.forNameentirely — and skip theClassNotFoundExceptionthrown for absent classes.SpanFactoryFactoryandScopesStorageFactorycalledisClassAvailable(X)and thenloadClass(X)— twoClass.forNamecalls for the same class. They now callloadClass(X)once and null-check.💡 Motivation and Context
Second of three stacked PRs reducing reflection cost on the init path (customer-provided Perfetto trace, Reduce SDK init time [Android]).
💚 How did you test it?
Existing
LoadClassTest, factory, andSentryinit tests pass; the cache returns identical availability results.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
PR 3 gates the Compose class probes behind the features that consume them.
⏱️ Pixel 3 benchmark (untraced timing)
Repeatedly probing the same absent class (2000 calls × 6 rounds; cache hits after the first miss):
forNameeach call)~188× faster for repeat probes — once the first miss caches
NOT_AVAILABLE, later probes skip both theClass.forNamecall and theClassNotFoundException. (Traced counts are noisy here due to background class loading, so this is measured untraced.)