Skip to content

perf(instrumentation): Resolve SDK class availability at build time - #1375

Merged
romtsn merged 13 commits into
mainfrom
romtsn/feat/java-654-sdk-optimization
Aug 7, 2026
Merged

perf(instrumentation): Resolve SDK class availability at build time#1375
romtsn merged 13 commits into
mainfrom
romtsn/feat/java-654-sdk-optimization

Conversation

@romtsn

@romtsn romtsn commented Jul 30, 2026

Copy link
Copy Markdown
Member

Resolve the availability of optional Sentry SDK classes from the app's dependency graph and inject the results into LoadClass during bytecode instrumentation. The optimization is independent from tracing instrumentation, enabled by default, and can be disabled with sentry.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

@linear-code

linear-code Bot commented Jul 30, 2026

Copy link
Copy Markdown

JAVA-654

romtsn added a commit that referenced this pull request Jul 30, 2026
Document the build-time SDK class availability optimization introduced in #1375.

Refs JAVA-654
Co-Authored-By: Codex <noreply@openai.com>
@romtsn
romtsn marked this pull request as ready for review July 30, 2026 14:44

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

One more thing, should we detect an incompatible version of the sentry-java sdk and then show an error?

Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt Outdated
@romtsn

romtsn commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

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 👍

romtsn and others added 8 commits August 7, 2026 12:59
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>
@romtsn
romtsn force-pushed the romtsn/feat/java-654-sdk-optimization branch from 46db4b3 to 59b2550 Compare August 7, 2026 10:59
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>

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread CHANGELOG.md Outdated
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

romtsn and others added 2 commits August 7, 2026 13:30
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>
@romtsn
romtsn merged commit cebd9e4 into main Aug 7, 2026
24 checks passed
@romtsn
romtsn deleted the romtsn/feat/java-654-sdk-optimization branch August 7, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants