RUM-18174: Fix long task duration computation - #3748
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes incorrect main-looper long-task durations and improves shared printer lifecycle and performance.
Changes:
- Resets dispatch state safely and ignores unmatched finish messages.
- Uses an identity-based, allocation-free printer registry.
- Expands lifecycle, duration, and concurrency tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
MainLooperLongTaskStrategy.kt |
Refactors duration tracking and printer registration. |
MainLooperLongTaskStrategyTest.kt |
Adds duration, lifecycle, and race tests. |
detekt_custom_safe_calls_third_party.yml |
Allows Array.isEmpty(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: f6cfce8 | Docs | View more details | Give us feedback! |
f5d9256 to
2207225
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 220722566e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2207225 to
f6cfce8
Compare
What does this PR do?
Fixes long task duration computation in
MainLooperLongTaskStrategyand reduce hot method impact of the SDK.The duration bug.
startUptimeNsdefaulted to0Land was never reset after a dispatch completed. Any<<<<< Finished tothat had no matching>>>>> Dispatching to— the first one afterregister(), or a repeated one for a dispatch already accounted for — computednow - 0, i.e. the entire device elapsed time, and reported it as a long task. On a device up for hours that surfaces as a multi-hour long task attached to whatever the main thread happened to be doing.Dispatch state is republished per registration.
register()installs a freshDispatcherStatebehind a@Volatilefield, so a strategy replaced while the main thread sits between a dispatch and its finish can no longer pair a start from before the swap with a finish from after it.CompositePrintercleanup.Loopermessage-logging printer is now uninstalled when the last strategy unregisters, soLooper.loop()stops building a log string for every message it dispatches once the SDK is stopped.MainLooperLongTaskStrategyrefactor .printlnexecutes on the ui thread. So object allocations and thread synchronization has been moved into other methods of theMainLooperLongTaskStrategy.Motivation
RUM-18174 — long tasks were being reported with durations spanning the device uptime instead of the actual dispatch.
Review checklist (to be filled by reviewers)