Repository navigation
feat(core): pass the display's frame time to RequestAnimationFrame - #1068
Merged
Merged
Conversation
RequestAnimationFrame's time was the engine clock's when the engine goroutine got to the frame, so a loop stepping by the difference between two frames carried the engine's scheduling jitter. Hosts now report the display's time with Engine.FrameAt and Scope.RunFrameAt: the display link's targetTimestamp on macOS and iOS, the animation frame's timestamp on the web, Choreographer's frameTimeNanos on Android, the GdkFrameClock's frame time on Linux, DwmFlush's return on Windows, displaySync's targetTimestamp on HarmonyOS and the TimelineView's date on watchOS. driver.DisplayTime moves time.Now by the difference between the display's stamp and the platform clock read with it; a frame's time never precedes the previous one's, and an engine with its own clock keeps that clock's time, so nsgotest stays deterministic. Linux ticks from the surface's GdkFrameClock rather than a 16 ms GLib timer, with a 100 ms watch ticking in its place while the frame clock stands still, as for a window not shown. The frame-clock tables in animation.md now name each target's source and time. Closes nsgo-dev#1048
The core may now give a frame's time up to a frame ahead of the clock, as macOS's and iOS's display links tell when the frame shows, so performance.now() - ts went negative, which no browser does. TSX holds the timestamp it passes to JS to the clock's now; core keeps its semantics.
… when the platform clock may be read The committed HarmonyOS host was not rebuilt and still calls nsgoFrame() without displaySync's time, so an app packaged without the OpenHarmony SDK gets the engine clock's. DisplayTime's doc and the animation architecture now say the platform clock may be read later on any goroutine, as Android reads it after the pipe, since the delay cancels out.
This was referenced Nov 21, 2026
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.
Scope.RequestAnimationFramenow gets the display frame's time where the platform gives one, instead of the engine clock's time when the engine goroutine got to the frame. Hosts report it withEngine.FrameAt, which runsScope.RunFrameAt;driver.DisplayTimereads the platform's stamp and its own clock together in the frame callback and movestime.Nowby the difference, so the time keeps the display's cadence however late the frame reaches the engine. A frame's time never precedes the previous one's, and an engine with an app clock of its own (engine.Options.Clock, as tests use) keeps that clock's time, sonsgotest'sAdvancestays deterministic.Each target's time: macOS and iOS the display link's
targetTimestamp(macOS falls back to the graph clock while a timer stands in for the link), the web therequestAnimationFrametimestamp, Android Choreographer'sframeTimeNanos(the Java runtime now sends it withFRAME;classes.dexandclasses.jarrebuilt), Linux theGdkFrameClock's frame time, Windows whenDwmFlushlast returned, HarmonyOSdisplaySync'stargetTimestamp, moved onto Go's clock by the bridge's quickest delivery seen (driver.DisplayClock), and watchOS theTimelineView's date. Mini programs keep their 16 ms timer and the graph clock, as the logic layer has no display frames.Linux now ticks from the surface's
GdkFrameClock(gtk_widget_add_tick_callback) instead of a 16 ms GLib timer, so it follows 120 and 144 Hz displays. While the frame clock stands still, as for a window not shown, a 100 ms watch ticks in its place so animations still end and the app's frames still come, as macOS's stall timer does.docs/architecture/animation.mdgets a table naming each target's frame source and what its time is, and its native-animation table now says Windows waits onDwmFlushand Linux ticks from the frame clock. The device acceptance (0.5 ms cadence on hardware, Linux at 120 Hz) is recorded indocs/roadmap.md, as only headless tests and builds ran.Validation:
ubuild mise exec [email protected] -- go tool nsgo check -target all -jobs 12rbuild mise exec [email protected] -- go tool nsgo check -target ios,ios_simulator,tvos,tvos_simulator,watchos,watchos_simulator -jobs 6ubuild mise exec [email protected] -- go tool nsgo test ./coreubuild mise exec [email protected] -- go tool nsgo test ./internal/engineubuild mise exec [email protected] -- go tool nsgo test ./internal/driverubuild mise exec [email protected] -- go tool nsgo test ./nsgotestubuild mise exec [email protected] -- go tool nsgo test ./internal/moduletestubuild mise exec [email protected] -- go tool nsgo test ./cmd/nsgo -- -run 'Harmony|Ets|Template'mise exec java@21 -- env ANDROID_HOME=$HOME/Library/Android/sdk sh internal/platform/android/runtime/build.shScreenshots
None
Closes #1048