Skip to content

WIP: Make touch to present latency on iOS match UIKit - #191388

Draft
knopp wants to merge 4 commits into
flutter:masterfrom
knopp:vsync3
Draft

knopp wants to merge 4 commits into
flutter:masterfrom
knopp:vsync3

Conversation

@knopp

@knopp knopp commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

This PR builds on top of #191368 to fix the last remaining issue - delaying CA commit until we have frame available. This gets rid of the second frame of latency.

This is a very hacky proof of concept PR that is cutting a lot of corners. But it works.

(Note that we can match UIKit while gesture is in progress, but the gesture starts slower because of recognizer logic differences. Also there is some weirdness in ScrollDragController._adjustForScrollStartThreshold that maybe need a look.)

zero-additional-latency.mov

List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@knopp
knopp requested review from a team as code owners August 19, 2026 22:57
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the iOS and macOS shell implementation to dispatch pointer events and request vsync frames synchronously, utilizing a shared FlutterRunLoop and a custom EmbedderTaskRunner. Feedback on these changes highlights critical issues: the synchronous execution of vsync callbacks during touch dispatch can cause infinite recursion and stack overflows, and capturing a raw task runner pointer in deferred blocks introduces a Use-After-Free vulnerability. Additionally, the use of global state variables breaks multi-engine support, and nestedly pumping the run loop during touch dispatch poses re-entrancy risks. Finally, the reviewer recommends removing commented-out code and #if 0 blocks to adhere to style guidelines.

Comment on lines +81 to +84
CFTimeInterval startTime = CACurrentMediaTime();
while (!FlutterDidPresentSurface && CACurrentMediaTime() - startTime < 0.5) {
[FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Pumping the run loop nestedly using pollFlutterMessagesOnce in a while loop on the main thread while holding the touch dispatch is highly risky. This can lead to unexpected re-entrancy issues where other events (timers, network callbacks, or other touch events) are processed in an unexpected state, potentially causing crashes or inconsistent UI state. It also risks blocking the main thread and triggering watchdog terminations if the frame presentation is delayed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is very reasonable risk of reentrancy issues because we have a custom run loop mode just for this.

@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. platform-macos Building on or for macOS specifically a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Aug 19, 2026
This we block after other UIKit widgets had chance to update.
@knopp knopp changed the title WIP: Make touch to present latency on iOS match AppKit WIP: Make touch to present latency on iOS match UIKit Aug 20, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@knopp
knopp marked this pull request as draft September 10, 2026 21:50
@flutter-dashboard

Copy link
Copy Markdown

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically platform-macos Building on or for macOS specifically team-ios Owned by iOS platform team team-macos Owned by the macOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant