Skip to content

perf: Reduce reflection cost during SDK init (Init Reflection stack)#5634

Merged
runningcode merged 2 commits into
mainfrom
no/perf-init-reflection
Jun 30, 2026
Merged

perf: Reduce reflection cost during SDK init (Init Reflection stack)#5634
runningcode merged 2 commits into
mainfrom
no/perf-init-reflection

Conversation

@runningcode

@runningcode runningcode commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

PR Stack (Init Reflection)


Part of JAVA-587

Collection PR for the Init Reflection stack — reducing the reflection cost on the SentryAndroid.init path (found via the customer-provided Perfetto trace in the Reduce SDK init time [Android] project).

Squash-merge this once all stack PRs below are merged into it.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Performance

- Reduce reflection cost during SDK init (Init Reflection stack) ([#5634](https://github.com/getsentry/sentry-java/pull/5634))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 7a978c6

@sentry

sentry Bot commented Jun 25, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.46.0 (1) release

⚙️ sentry-android Build Distribution Settings

@linear-code

linear-code Bot commented Jun 25, 2026

Copy link
Copy Markdown

JAVA-587

@runningcode runningcode marked this pull request as ready for review June 30, 2026 09:03
@runningcode runningcode force-pushed the no/perf-init-reflection branch from 4b31414 to a11693e Compare June 30, 2026 09:05
…ializing (#5635)

* perf(core): Probe class availability without initializing the class

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>

* changelog

* changelog: move init reflection entries to Performance

* perf(core): Limit no-init class probing to isClassAvailable

The previous change made loadClass itself skip class initialization,
which affected callers that load a class to actually use it (NDK
integration, OTEL span factory and scopes storage). Restore loadClass
to its initializing behavior and confine the non-initializing probe to
isClassAvailable, which is only ever used for classpath availability
checks. This keeps SDK init cheap while leaving real-use callers
unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@runningcode runningcode enabled auto-merge (squash) June 30, 2026 09:13
@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 315.22 ms 348.00 ms 32.78 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
1edbdfa 364.77 ms 450.29 ms 85.52 ms
a416a65 333.78 ms 410.37 ms 76.59 ms
d15471f 302.62 ms 353.84 ms 51.22 ms
22f4345 314.79 ms 375.02 ms 60.23 ms
6b019b7 343.31 ms 417.23 ms 73.91 ms
22f4345 312.78 ms 347.40 ms 34.62 ms
d217708 411.22 ms 430.86 ms 19.63 ms
319f256 315.96 ms 372.96 ms 57.00 ms
e2dce0b 308.96 ms 360.10 ms 51.14 ms
8558cac 306.16 ms 355.24 ms 49.09 ms

App size

Revision Plain With Sentry Diff
1edbdfa 1.58 MiB 2.20 MiB 635.34 KiB
a416a65 1.58 MiB 2.12 MiB 555.26 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
6b019b7 0 B 0 B 0 B
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
319f256 1.58 MiB 2.19 MiB 619.79 KiB
e2dce0b 0 B 0 B 0 B
8558cac 0 B 0 B 0 B

@runningcode runningcode merged commit 8fe8bad into main Jun 30, 2026
69 of 70 checks passed
@runningcode runningcode deleted the no/perf-init-reflection branch June 30, 2026 09:20
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