Skip to content

perf(android): mini optimization: Guard manifest metadata debug logs behind isEnabled#5790

Open
runningcode wants to merge 2 commits into
mainfrom
no/java-614-reduce-logging-allocation-overhead
Open

perf(android): mini optimization: Guard manifest metadata debug logs behind isEnabled#5790
runningcode wants to merge 2 commits into
mainfrom
no/java-614-reduce-logging-allocation-overhead

Conversation

@runningcode

@runningcode runningcode commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

📜 Description

This is a mini optimization, this just reduces GC churn in the manifest reading which is a very expensive part of the startup.

This wraps each of the six helpers in a logger.isEnabled(SentryLevel.DEBUG) guard so the message is only built when debug logging is actually enabled. The guard is exactly the condition DiagnosticLogger.log already applies internally, so behavior is unchanged.

Closes #5700

💚 How did you test it?

Existing ManifestMetadataReaderTest coverage exercises these helpers. The change is behavior-preserving (only defers message construction), and sentry-android-core compiles with apiDump producing no .api changes.

📝 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

None.

…AVA-614)

The read helpers in ManifestMetadataReader built the debug message
(key + " read: " + value) unconditionally at the call site, and
DiagnosticLogger only filtered on options.isDebug() afterward. With
debug=false (the default) that discarded ~100 StringBuilder/String
allocations per init.

Guard the six read helpers with logger.isEnabled(DEBUG) so the message
is only constructed when debug logging is actually on. Behavior is
unchanged; this is a pure allocation/GC-pressure reduction on the init
path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jul 20, 2026

Copy link
Copy Markdown

JAVA-614

@sentry

sentry Bot commented Jul 20, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 311.98 ms 363.90 ms 51.92 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
5b1a06b 310.56 ms 362.79 ms 52.22 ms
ad8da22 339.92 ms 407.37 ms 67.45 ms
d15471f 307.28 ms 381.85 ms 74.57 ms
2195398 345.88 ms 411.71 ms 65.82 ms
ee747ae 396.82 ms 441.67 ms 44.86 ms
abfcc92 304.04 ms 370.33 ms 66.29 ms
22f4345 312.78 ms 347.40 ms 34.62 ms
d15471f 304.55 ms 408.43 ms 103.87 ms
ad8da22 362.98 ms 453.94 ms 90.96 ms
bbc35bb 298.53 ms 372.17 ms 73.64 ms

App size

Revision Plain With Sentry Diff
5b1a06b 0 B 0 B 0 B
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
2195398 0 B 0 B 0 B
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB

final boolean defaultValue) {
final boolean value = metadata.getBoolean(key, defaultValue);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
if (logger.isEnabled(SentryLevel.DEBUG)) {

@runningcode runningcode Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could provide a new api to build the strings inside a lambda like Timber does. I wonder if customers have asked for this.

@runningcode runningcode changed the title perf(android): Guard manifest metadata debug logs behind isEnabled perf(android): mini optimization: Guard manifest metadata debug logs behind isEnabled Jul 20, 2026
@runningcode
runningcode marked this pull request as ready for review July 20, 2026 14:44
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.

Reduce logging allocation overhead on the init path

1 participant