Reduce iOS pointer latency by dispatching pending input before BeginFrame - #190918
Open
MTtankkeo wants to merge 3 commits into
Open
Reduce iOS pointer latency by dispatching pending input before BeginFrame#190918MTtankkeo wants to merge 3 commits into
MTtankkeo wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a pre-frame vsync callback mechanism to the Flutter engine, allowing work such as input dispatching to execute immediately before the primary frame callback of a vsync interval. The review feedback identifies a thread-safety issue in Animator::RequestFrame where AwaitVSync could be called synchronously on a non-UI thread, and a potential race condition in VsyncWaiter under high load when using a boolean to track vsync fire progress.
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.
Description
Fixes #190917
On iOS,
SmoothPointerDataDispatchermay hold the latest pointer packet until VSync to smooth irregular input delivery.Previously, the pending packet was released from a secondary VSync callback, after the primary frame callback for that VSync had already been posted.
As a result, pointer data synchronized to VSync N could not affect the frame associated with VSync N. If processing that pointer data requested a frame, the request would instead wait for VSync N+1, adding a full display interval to the input-to-render path.
In other words, the pointer packet was synchronized to one VSync but could only be rendered by the following one.
Changes
This change adds a bounded pre-frame callback phase to
VsyncWaiter.The callback order becomes:
SmoothPointerDataDispatchernow releases its pending pointer packet during the pre-frame phase instead of from a secondary callback.The primary callback is intentionally left available until pre-frame work has completed. If processing the pointer packet requests a frame while the platform VSync has already fired but its primary callback has not yet been consumed,
Animatorregisters that callback synchronously.This allows the newly requested frame to participate in the current VSync rather than posting
AwaitVSyncbehind the already queued primary-frame task and waiting for the following VSync.The same-VSync registration window is deliberately narrow. It begins when the platform VSync fires and ends when the primary callback is consumed on the UI task runner. Pre-frame or secondary callbacks registered after the current callback snapshot are kept for the next VSync.
This preserves the existing smoothing behavior of
SmoothPointerDataDispatcher. The change only ensures that pointer data released for a VSync can be consumed by the frame associated with that same VSync.Before and after
Before:
After:
The pending pointer packet is still synchronized to VSync, but it no longer incurs an additional frame solely because it was dispatched after the primary callback.
Tests
Added coverage verifies that:
SmoothPointerDataDispatcheris dispatched before the primary callback and can be consumed by the frame associated with the same VSync.Pre-launch Checklist
///).