Repository navigation
Conversation
The CADisplayLink used to measure JS frame times stops ticking while the app is in the background, but lastFrameTimestamp was never reset, so the first frame after resuming was reported as a JS long task spanning the whole background duration. JSRefreshRateMonitor already had appWillResignActive/appDidBecomeActive hooks, but nothing called them. Observe UIApplication willResignActive/didBecomeActive to stop/restart the listener, and reset lastFrameTimestamp on start, matching Android's FrameRateProvider and the native iOS SDK. Fixes #1523 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: mariedm <29802155+mariedm@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Workflow Automation • View in Workflow Automation
Fixes #1523. On iOS, the JS refresh rate listener now pauses when the app resigns active and restarts when it becomes active again. The first frame after a restart begins a new measurement instead of being compared with the last frame from before the pause.
JSRefreshRateMonitorobservesUIApplication.willResignActiveNotificationanddidBecomeActiveNotification. These now call the existingappWillResignActiveandappDidBecomeActivehooks, which nothing called before. The handlers hop onto the shared SDK queue, becausestartMonitoringreplaces the listener on that queue and the notifications arrive on the main thread.JSRefreshRateListener.start()resetslastFrameTimestampon the JS thread before it creates the newCADisplayLink.onFrame(timestamp:targetTimestamp:), so the behavior can be unit-tested.Motivation
CADisplayLinkstops ticking while the app is in the background, butlastFrameTimestampwas never reset. The first tick after foregrounding was therefore measured against the last tick before backgrounding. That produced onelong_task.target: javascriptevent, plus a matching JS refresh rate sample, lasting the whole time the app was in the background. Android already handles this:FrameRateProvider.start()resets the frame time and is driven byonHostPause/onHostResume. The native iOS SDK's refresh rate reader does the same using the same two notifications.Trade-off: like the native iOS SDK, JS frames are not measured while the app is inactive but still on screen, for example while Control Center or an incoming-call banner is showing.
Additional Notes
Testing:
JSRefreshRateMonitorTests:willResignActiveand restarted ondidBecomeActive;longTaskThresholdMs, wait, foreground it, and confirm no JS long task appears for the background duration.Review checklist (to be filled by reviewers)
🤖 Generated with Claude Code (link removed)
PR by Bits - View session in Datadog
Comment @DataDog to request changes