Skip to content

perf(core): Skip Hint allocation in addBreadcrumb without callback#5689

Open
runningcode wants to merge 1 commit into
mainfrom
no/java-605-avoid-hint-allocation
Open

perf(core): Skip Hint allocation in addBreadcrumb without callback#5689
runningcode wants to merge 1 commit into
mainfrom
no/java-605-avoid-hint-allocation

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

Resolves JAVA-605.

Description

Scope.addBreadcrumb(Breadcrumb, Hint) allocated a Hint unconditionally when the caller passed null, even though the Hint is only ever used to pass to the beforeBreadcrumb callback. When no callback is configured (the common case) the Hint — a HashMap + ArrayList + AutoClosableReentrantLock — was created and immediately discarded on every breadcrumb.

This moves the allocation inside the callback != null branch, so no Hint is allocated on the common path.

Pure allocation elimination, no behavior change.

Source

Found via on-device Perfetto method-trace analysis of the Android SDK (Scope#addBreadcrumb breadcrumb path). Part of Reduce SDK init time [Android].

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Jul 2, 2026

Copy link
Copy Markdown

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>
@runningcode runningcode force-pushed the no/java-605-avoid-hint-allocation branch from 88119b9 to 3680ae4 Compare July 2, 2026 16:50
@sentry

sentry Bot commented Jul 2, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@runningcode runningcode marked this pull request as ready for review July 2, 2026 16:53
@runningcode runningcode marked this pull request as draft July 2, 2026 16:57
@runningcode runningcode marked this pull request as ready for review July 2, 2026 17:05
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 354.71 ms 435.38 ms 80.67 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
abfcc92 304.04 ms 370.33 ms 66.29 ms
4e3e79d 365.83 ms 477.62 ms 111.79 ms
d8912da 329.94 ms 389.68 ms 59.74 ms
d15471f 294.13 ms 399.49 ms 105.36 ms
abf451a 332.82 ms 403.67 ms 70.85 ms
604a261 380.65 ms 451.27 ms 70.62 ms
806307f 357.85 ms 424.64 ms 66.79 ms
22f4345 307.87 ms 354.51 ms 46.64 ms
d217708 375.27 ms 415.68 ms 40.41 ms
c3ee041 310.64 ms 361.90 ms 51.26 ms

App size

Revision Plain With Sentry Diff
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
4e3e79d 0 B 0 B 0 B
d8912da 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
abf451a 1.58 MiB 2.20 MiB 635.29 KiB
604a261 1.58 MiB 2.10 MiB 533.42 KiB
806307f 1.58 MiB 2.10 MiB 533.42 KiB
22f4345 1.58 MiB 2.29 MiB 719.83 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
c3ee041 0 B 0 B 0 B

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