Skip to content

perf(android): Use build-time manifest metadata - #5963

Closed
romtsn wants to merge 2 commits into
mainfrom
perf/java-531-build-time-manifest
Closed

perf(android): Use build-time manifest metadata#5963
romtsn wants to merge 2 commits into
mainfrom
perf/java-531-build-time-manifest

Conversation

@romtsn

@romtsn romtsn commented Aug 13, 2026

Copy link
Copy Markdown
Member

📜 Description

Allow the Sentry Android Gradle plugin to inject resolved manifest metadata into
ManifestMetadataReader. The injected map is authoritative and read directly;
older plugin versions and unresolved manifests keep using the existing
PackageManager/Bundle path.

💡 Motivation and Context

Android SDK initialization currently calls getApplicationInfo(GET_META_DATA) and
lazily unparcels its metadata bundle on the startup path. Moving resolvable
io.sentry.* values to build time avoids both operations without changing manifest
option behavior.

Refs JAVA-531

💚 How did you test it?

  • ./gradlew spotlessApply apiDump :sentry-android-core:testReleaseUnitTest --tests '*ManifestMetadataReaderTest*'
  • Validated all 98 supported manifest keys in a real app in injected and fallback modes
  • Confirmed in Perfetto that both startup getApplicationInfo calls disappear when injected
  • Compared 24 cold starts per mode; direct-map init median improved from 32.987 ms to 30.835 ms

📝 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.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

The companion Sentry Android Gradle plugin PR injects the map for compatible SDK versions:
getsentry/sentry-android-gradle-plugin#1401

Allow the Android Gradle plugin to provide authoritative manifest metadata so SDK initialization can skip PackageManager and Bundle unparceling. Read the injected map directly to avoid conversion overhead.

Refs JAVA-531
Co-Authored-By: Codex <noreply@openai.com>
@linear-code

linear-code Bot commented Aug 13, 2026

Copy link
Copy Markdown

JAVA-531

@sentry

sentry Bot commented Aug 13, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 287.18 ms 364.91 ms 77.74 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
9e60aca 316.18 ms 345.04 ms 28.86 ms
6b019b7 403.90 ms 546.09 ms 142.19 ms
d15471f 310.66 ms 368.19 ms 57.53 ms
d217708 375.27 ms 415.68 ms 40.41 ms
22f4345 314.79 ms 375.02 ms 60.23 ms
fcec2f2 328.91 ms 387.75 ms 58.84 ms
d501a7e 307.33 ms 341.94 ms 34.61 ms
7414e9b 315.69 ms 367.66 ms 51.97 ms
fcec2f2 314.96 ms 373.66 ms 58.70 ms
e2dce0b 308.96 ms 360.10 ms 51.14 ms

App size

Revision Plain With Sentry Diff
9e60aca 0 B 0 B 0 B
6b019b7 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.50 KiB
d501a7e 0 B 0 B 0 B
7414e9b 0 B 0 B 0 B
fcec2f2 1.58 MiB 2.12 MiB 551.50 KiB
e2dce0b 0 B 0 B 0 B

Refs JAVA-531
Co-Authored-By: Codex <noreply@openai.com>
@romtsn
romtsn marked this pull request as ready for review August 13, 2026 11:45
Comment on lines +872 to +874
raw instanceof Float
? ((Float) raw).doubleValue()
: raw instanceof Integer ? ((Integer) raw).doubleValue() : -1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The readDouble method doesn't handle Double types from the build-time metadata map. Sample rates from the Gradle plugin will be silently ignored as they default to Double.
Severity: MEDIUM

Suggested Fix

Update the readDouble method to handle Double instances from the build-time metadata map. Add a check for raw instanceof Double and cast the value to double before returning it, similar to how Float and Integer are currently handled.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java#L872-L874

Potential issue: The `readDouble` method, when reading from the build-time metadata Map,
only handles `Float` and `Integer` types. It does not handle `Double` types. In Kotlin,
which the Sentry Gradle plugin uses, decimal literals like `0.5` are inferred as
`Double`. If the Gradle plugin is used to configure a sample rate (e.g.,
`tracesSampleRate = 0.5`), it will be passed as a `Double`. The `readDouble` method will
then silently return `-1`, causing the sample rate configuration to be ignored and
sampling to be disabled or fall back to a default value.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The plugin does not pass Kotlin decimal literals into this field. ManifestMetadataParser.inferType explicitly uses toFloatOrNull(), so 0.5 becomes a Float; ManifestMetadataClassVisitor then boxes it with Float.valueOf. The parser test also asserts 0.5f, and this intentionally mirrors the Float type returned by Android manifest metadata. A Double therefore cannot be produced by the build-time injection path.

@romtsn

romtsn commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

Superseded by a generated app-class design. The replacement keeps app-specific metadata out of dependency transform inputs so AGP can cache the SDK transform correctly and Gradle can model manifest generation through its normal source pipeline.

@romtsn romtsn closed this Aug 13, 2026
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