Skip to content

Commit 1916876

Browse files
runningcodeclaude
andcommitted
perf(core): Skip Hint allocation in addBreadcrumb (JAVA-605)
Only allocate a Hint when a beforeBreadcrumb callback is set. addBreadcrumb previously allocated a Hint (HashMap + ArrayList + lock) on every call even though the Hint is only ever passed to the callback, wasting allocations on the common no-callback path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dfd01a3 commit 1916876

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
- Name the device-info caching thread `SentryDeviceInfoCache` so all threads spawned by the SDK are identifiable ([#5684](https://github.com/getsentry/sentry-java/pull/5684))
1414
- Apply byte-category rate limits to log and trace metric envelope items ([#5716](https://github.com/getsentry/sentry-java/pull/5716))
1515

16+
### Performance
17+
18+
- Skip `Hint` allocation in `Scope.addBreadcrumb` when no `beforeBreadcrumb` callback is set ([#5689](https://github.com/getsentry/sentry-java/pull/5689))
19+
1620
## 8.47.0
1721

1822
### Behavioral Changes

sentry/src/main/java/io/sentry/Scope.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,11 @@ public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) {
493493
if (breadcrumb == null || breadcrumbs instanceof DisabledQueue) {
494494
return;
495495
}
496-
if (hint == null) {
497-
hint = new Hint();
498-
}
499-
500496
SentryOptions.BeforeBreadcrumbCallback callback = options.getBeforeBreadcrumb();
501497
if (callback != null) {
498+
if (hint == null) {
499+
hint = new Hint();
500+
}
502501
breadcrumb = executeBeforeBreadcrumb(callback, breadcrumb, hint);
503502
}
504503
if (breadcrumb != null) {

0 commit comments

Comments
 (0)