Skip to content

perf(android): [SDK Overhead Reduction 2] Replace reflective OptionsContainer with direct subclass#5501

Draft
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-options-container
Draft

perf(android): [SDK Overhead Reduction 2] Replace reflective OptionsContainer with direct subclass#5501
adinauer wants to merge 1 commit into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-options-container

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Jun 5, 2026

PR Stack (SDK Overhead Reduction)


📜 Description

Replace OptionsContainer.create(SentryAndroidOptions.class) — which uses getDeclaredConstructor().newInstance() — with a direct SentryAndroidOptionsContainer subclass that returns new SentryAndroidOptions() without reflection.

To enable subclassing, OptionsContainer is made non-final (@Open) with a protected no-arg constructor. The clazz field becomes @Nullable with a null check in createInstance() for the reflective path (used by non-Android callers).

💡 Motivation and Context

Part of the SDK Overhead Reduction stack. Avoids reflective constructor invocation on the Android cold-start path. While the improvement is below the noise floor in isolation (AR-71 in autoresearch report), it removes unnecessary reflection and is a clean, risk-free change.

💚 How did you test it?

  • ./gradlew :sentry:test — all tests pass
  • ./gradlew :sentry-android-core:testDebugUnitTest — all tests pass
  • ./gradlew spotlessApply apiDump — API change is only the expected non-final + protected ctor

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

More SDK overhead reduction PRs in this stack.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

#skip-changelog

Replace OptionsContainer.create(SentryAndroidOptions.class) which uses
getDeclaredConstructor().newInstance() with a direct
SentryAndroidOptionsContainer subclass that returns
new SentryAndroidOptions() without reflection.

Make OptionsContainer non-final (@OPEN) with a protected no-arg
constructor so Android can subclass it.
@sentry
Copy link
Copy Markdown

sentry Bot commented Jun 5, 2026

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 311.23 ms 337.56 ms 26.33 ms
Size 0 B 0 B 0 B

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.

1 participant