perf(instrumentation): Resolve SDK class availability at build time - #1375
Conversation
Document the build-time SDK class availability optimization introduced in #1375. Refs JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
runningcode
left a comment
There was a problem hiding this comment.
Looks good!
One more thing, should we detect an incompatible version of the sentry-java sdk and then show an error?
we usually don't do that, since we check for the runtime sdk version and gracefully fallback, but I've added an info log anyway 👍 |
Add an independently configurable ASM visitor that derives known optional classes from resolved modules and injects their availability into LoadClass. Avoid repeated reflection during SDK startup. Refs JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Document the build-time SDK class availability optimization introduced in #1375. Refs JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Use zero placeholders and document that visitMaxs triggers frame and max computation. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Document the generated runtime state and reflection fallback. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Pass resolved class availability as an instrumentation input so dependency changes invalidate cached output and variants cannot read shared mutable state. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Name the configuration after its runtime effect and document the associated build-time cost. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Explain at info level when the current Sentry SDK cannot use the runtime reflection-check optimization. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Describe the eliminated reflection checks, relative benchmark results, uncertainty, and the opt-out setting. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
46db4b3 to
59b2550
Compare
Keep the pending runtime optimization change out of the released 6.17.0 section after rebasing. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Keep the headline SDK initialization result and opt-out guidance while leaving detailed measurements in the PR. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5a9e232. Configure here.
Skip SDK runtime optimization instrumentation when a variant runtime classpath cannot be found. Preserve reflection as the safe fallback instead of marking every optional class absent. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Keep the SDK optimization factory registered when class availability is unknown. Skip only LoadClass instrumentation so future optimizations remain independent. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>
Document why unknown class availability skips the LoadClass transformation. Refs LINEAR-JAVA-654 Co-Authored-By: Codex <noreply@openai.com>

Resolve the availability of optional Sentry SDK classes from the app's dependency graph and inject the results into
LoadClassduring bytecode instrumentation. The optimization is independent from tracing instrumentation, enabled by default, and can be disabled withsentry.sdkOptimization.enabled = false.The visitor safely ignores older SDK versions without the availability field. Applications using the supporting SDK avoid reflective availability probes during startup, while unknown class names still fall back to reflection.
Supporting SDK change: getsentry/sentry-java#5875
On a Pixel 2 XL, map construction and lookups were about 160× faster than the equivalent absent-heavy 11-class reflection batch. In the absent-heavy startup macrobenchmark, SDK initialization was 1.08% faster and full startup was 0.88% faster, though variance exceeded the measured delta. The representative 10-present/1-absent case showed no measurable improvement.
Verified with Spotless and focused visitor/plugin tests.
Refs JAVA-654