Title: Defer SentryFrameMetricsCollector thread startup · Issue #5483 · getsentry/sentry-java · GitHub
Open Graph Title: Defer SentryFrameMetricsCollector thread startup · Issue #5483 · getsentry/sentry-java
X Title: Defer SentryFrameMetricsCollector thread startup · Issue #5483 · getsentry/sentry-java
Description: SentryFrameMetricsCollector created and started its HandlerThread in the constructor and then called new Handler(handlerThread.getLooper()). getLooper() blocks the caller until the new thread's looper is ready — and the collector is cons...
Open Graph Description: SentryFrameMetricsCollector created and started its HandlerThread in the constructor and then called new Handler(handlerThread.getLooper()). getLooper() blocks the caller until the new thread's loo...
X Description: SentryFrameMetricsCollector created and started its HandlerThread in the constructor and then called new Handler(handlerThread.getLooper()). getLooper() blocks the caller until the new thread's...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/5483
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Defer SentryFrameMetricsCollector thread startup","articleBody":"`SentryFrameMetricsCollector` created and started its `HandlerThread` in the constructor and then called `new Handler(handlerThread.getLooper())`. `getLooper()` blocks the caller until the new thread's looper is ready — and the collector is constructed on the **main thread** during `SentryAndroid.init` (`loadDefaultAndMetadataOptions`).\n\nThe customer-provided Perfetto trace (`sentryinvest`) showed the main thread blocking ~5.75 ms on `HandlerThread.getLooper()` during init via `SentryFrameMetricsCollector.\u003cinit>`.\n\n## Fix\n\nThe `handler` is only used by `trackCurrentWindow()`, which no-ops until a listener is registered via `startCollection()`. Start the `HandlerThread` lazily on the first `startCollection()` (profiling / `SpanFrameMetricsCollector`). The constructor still registers the activity-lifecycle callback (current-window tracking unchanged) but no longer blocks. Apps that never collect frame metrics never start the thread at all.\n\nReusing the SDK's shared executor isn't viable: `addOnFrameMetricsAvailableListener` requires a dedicated non-main-thread `Handler` (Looper), which the shared `ScheduledExecutorService` doesn't provide.\n\n## Pixel 3 benchmark (Android 12, ART method trace → Perfetto trace_processor)\n\nConstructor `HandlerThread.getLooper()` / blocking `Object.wait()` slices: **old = 1 / 1 → new = 0 / 0**. The synchronous main-thread wait is removed from construction.\n\n## PR\n\n#5641","author":{"url":"https://github.com/apps/linear-code","@type":"Person","name":"linear-code"},"datePublished":"2026-05-29T09:07:58Z","url":"https://github.com/getsentry/sentry-java/issues/5483"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92be74ed-77dd-0173-c92c-d7de82767fea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BDFC:3C07AF:1D24B7:289815:6B0466F5 |
| html-safe-nonce | 2d0d6a784d0386e93c0bf446f332ebf32ebec1b6fbebdd848bd546704c9da488 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREZDOjNDMDdBRjoxRDI0Qjc6Mjg5ODE1OjZCMDQ2NkY1IiwidmlzaXRvcl9pZCI6IjI0MDg0OTM4ODQ3Mjk3NDcxODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 09c88196fc8428bbe67d3455b06a4e197af36f0e5841ac5193708377334943cc |
| hovercard-subject-tag | issue:4547224636 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5483/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0fc4344828e8b437f2d181381bab244a15d7d97f744c36032e25cbdf3c744df4/getsentry/sentry-java/issues/5483 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0fc4344828e8b437f2d181381bab244a15d7d97f744c36032e25cbdf3c744df4/getsentry/sentry-java/issues/5483 |
| og:image:alt | SentryFrameMetricsCollector created and started its HandlerThread in the constructor and then called new Handler(handlerThread.getLooper()). getLooper() blocks the caller until the new thread's loo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | linear-code[bot] |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width