perf(android): Use build-time manifest metadata - #5963
Conversation
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>
📲 Install BuildsAndroid
|
Performance metrics 🚀
|
| 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>
| raw instanceof Float | ||
| ? ((Float) raw).doubleValue() | ||
| : raw instanceof Integer ? ((Integer) raw).doubleValue() : -1; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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. |
📜 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/Bundlepath.💡 Motivation and Context
Android SDK initialization currently calls
getApplicationInfo(GET_META_DATA)andlazily unparcels its metadata bundle on the startup path. Moving resolvable
io.sentry.*values to build time avoids both operations without changing manifestoption behavior.
Refs JAVA-531
💚 How did you test it?
./gradlew spotlessApply apiDump :sentry-android-core:testReleaseUnitTest --tests '*ManifestMetadataReaderTest*'getApplicationInfocalls disappear when injected📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
The companion Sentry Android Gradle plugin PR injects the map for compatible SDK versions:
getsentry/sentry-android-gradle-plugin#1401