Skip to content

Commit 01572ad

Browse files
runningcodeclaude
andauthored
perf(android): mini optimization: Guard manifest metadata debug logs behind isEnabled (#5790)
* perf(android): Guard manifest metadata debug logs behind isEnabled (JAVA-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> * changelog --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bbcf99a commit 01572ad

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Improvements
6+
7+
- Skip building Android manifest metadata debug log messages when debug logging is disabled, reducing allocations during SDK init ([#5790](https://github.com/getsentry/sentry-java/pull/5790))
8+
59
### Fixes
610

711
- Pin the published Sentry Android SDK's AAR metadata `minCompileSdk` to our `minSdk` (`21`) instead of AGP 9's new default of the SDK's own `compileSdk` (`37`), so apps that depend on the SDK aren't forced to raise their `compileSdk` ([#5823](https://github.com/getsentry/sentry-java/pull/5823))

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ private static boolean readBool(
779779
final @NotNull String key,
780780
final boolean defaultValue) {
781781
final boolean value = metadata.getBoolean(key, defaultValue);
782-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
782+
if (logger.isEnabled(SentryLevel.DEBUG)) {
783+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
784+
}
783785
return value;
784786
}
785787

@@ -789,7 +791,9 @@ private static boolean readBool(
789791
final @NotNull String key,
790792
final @Nullable String defaultValue) {
791793
final String value = metadata.getString(key, defaultValue);
792-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
794+
if (logger.isEnabled(SentryLevel.DEBUG)) {
795+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
796+
}
793797
return value;
794798
}
795799

@@ -799,14 +803,18 @@ private static boolean readBool(
799803
final @NotNull String key,
800804
final @NotNull String defaultValue) {
801805
final String value = metadata.getString(key, defaultValue);
802-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
806+
if (logger.isEnabled(SentryLevel.DEBUG)) {
807+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
808+
}
803809
return value;
804810
}
805811

806812
private static @Nullable List<String> readList(
807813
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
808814
final String value = metadata.getString(key);
809-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
815+
if (logger.isEnabled(SentryLevel.DEBUG)) {
816+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
817+
}
810818
if (value != null) {
811819
return Arrays.asList(value.split(",", -1));
812820
} else {
@@ -821,7 +829,9 @@ private static double readDouble(
821829
if (value == -1) {
822830
value = ((Integer) metadata.getInt(key, -1)).doubleValue();
823831
}
824-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
832+
if (logger.isEnabled(SentryLevel.DEBUG)) {
833+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
834+
}
825835
return value;
826836
}
827837

@@ -832,7 +842,9 @@ private static long readLong(
832842
final long defaultValue) {
833843
// manifest meta-data only reads int if the value is not big enough
834844
final long value = metadata.getInt(key, (int) defaultValue);
835-
logger.log(SentryLevel.DEBUG, key + " read: " + value);
845+
if (logger.isEnabled(SentryLevel.DEBUG)) {
846+
logger.log(SentryLevel.DEBUG, key + " read: " + value);
847+
}
836848
return value;
837849
}
838850

0 commit comments

Comments
 (0)