This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Fix janks caused by await vsync in classical Flutter #36911
Closed
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.
This fixes the jank happened in classical Flutter, even without the existence of flutter_smooth
I will add tests and refine code etc after some code review - since review may request changing the code :)
This works pretty well in flutter_smooth, see https://github.com/fzyzcjy/engine/blob/flutter-smooth/shell/common/animator.cc for full code.
During experiments, I observe a phenomenon: Even when the UI thread finishes everything before the deadline (vsync) a few milliseconds, the next frame is scheduled one vsync later, causing one jank. For example, UI thread may run from 0-15ms, but the next frame starts from 33.33ms instead of the correct 16.67ms.
An example screenshot can be seen at the end of this proposal. I added a timeline event,
Animator::AwaitVSync
, so we can clearly see when vsync await is called. (This screenshot has roughly 3ms space; but more frequently, I see this bug when there is about 0.5-2ms space.)Therefore, this PR tries to fix this problem. The main idea is that, when detecting we are very near the next vsync, we do not wait at all, but instead directly start the next frame.
zoom in:
further zoom in:
Pre-launch Checklist
writing and running engine tests. -- see above
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.