Skip to content

RUM-18174: Fix long task duration computation - #3748

Open
satween wants to merge 1 commit into
developfrom
tvaleev/feature/RUM-18174
Open

RUM-18174: Fix long task duration computation#3748
satween wants to merge 1 commit into
developfrom
tvaleev/feature/RUM-18174

Conversation

@satween

@satween satween commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes long task duration computation in MainLooperLongTaskStrategy and reduce hot method impact of the SDK.

The duration bug. startUptimeNs defaulted to 0L and was never reset after a dispatch completed. Any <<<<< Finished to that had no matching >>>>> Dispatching to — the first one after register(), or a repeated one for a dispatch already accounted for — computed now - 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 fresh DispatcherState behind a @Volatile field, 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.

CompositePrinter cleanup.

  • The main Looper message-logging printer is now uninstalled when the last strategy unregisters, so Looper.loop() stops building a log string for every message it dispatches once the SDK is stopped.

MainLooperLongTaskStrategy refactor .

  • println executes on the ui thread. So object allocations and thread synchronization has been moved into other methods of the MainLooperLongTaskStrategy.

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)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@satween
satween requested a balanced review from Copilot August 20, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 20, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 85.37%
Overall Coverage: 71.79% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f6cfce8 | Docs | View more details | Give us feedback!

@satween
satween force-pushed the tvaleev/feature/RUM-18174 branch from f5d9256 to 2207225 Compare August 21, 2026 10:51
@satween
satween marked this pull request as ready for review August 21, 2026 10:55
@satween
satween requested review from a team as code owners August 21, 2026 10:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@satween
satween force-pushed the tvaleev/feature/RUM-18174 branch from 2207225 to f6cfce8 Compare August 21, 2026 11:12
@satween
satween requested a review from 0xnm August 21, 2026 11:12
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.

2 participants