perf(core): [Init Reflection 1] Probe class availability without initializing#5635
Open
runningcode wants to merge 3 commits into
Open
perf(core): [Init Reflection 1] Probe class availability without initializing#5635runningcode wants to merge 3 commits into
runningcode wants to merge 3 commits into
Conversation
LoadClass.loadClass used Class.forName(name) which initializes the class. Used purely for availability probing during init, this eagerly runs unrelated static initializers (e.g. Compose's Owner, the fragment integration). Use Class.forName(name, false, classLoader) so the class is only initialized lazily on first real use. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 25, 2026
📲 Install BuildsAndroid
|
3 tasks
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
LoadClass.loadClassusedClass.forName(name), which initializes the class. Since this method is used purely to probe whether an optional integration is on the classpath duringSentryAndroid.init, that eagerly runs unrelated static initializers — the customer trace showsandroidx.compose.ui.node.Owner.<clinit>andFragmentLifecycleIntegration.<clinit>executing under the availability check.This switches to
Class.forName(name, false, classLoader)so the class is loaded but only initialized lazily on first real use (e.g. when it's actually instantiated).💡 Motivation and Context
First of three stacked PRs reducing reflection cost on the init path, from the customer-provided Perfetto trace in the Reduce SDK init time [Android] project (JAVA-586 area).
💚 How did you test it?
New
LoadClassTestincluding a guard asserting that probing a class does not run its static initializer; existing init/integration tests pass unchanged.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
PR 2 caches lookups and collapses double-probes; PR 3 gates the Compose probes behind their features.
⏱️ Pixel 3 benchmark (ART method trace → Perfetto trace_processor)
Probing a class that has a (deliberately heavy) static initializer:
Class.forName(name)Class.forName(name, false, loader)<clinit>invocations under the probeThe static initializer runs under the old probe and is entirely skipped under the new one. In the production trace this was
androidx.compose.ui.node.Owner.<clinit>andFragmentLifecycleIntegration.<clinit>running during init. (Method tracing inflates the absolute<clinit>time, so only the invocation count is reported.)