Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter adds additional one frame touch latency compared to native #110431

Open
knopp opened this issue Aug 28, 2022 · 25 comments
Open

Flutter adds additional one frame touch latency compared to native #110431

knopp opened this issue Aug 28, 2022 · 25 comments
Labels
a: fidelity Matching the OEM platforms better engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@knopp
Copy link
Member

knopp commented Aug 28, 2022

Bad Expected
tracking-bad.mov
tracking-expected.mov

Repository: https://github.com/knopp/flutter_scroll_overlay

When touch event is received, instead of immediately beginning a frame Flutter waits for next vsync. But that skips an entire frame. By the time vsync comes, the frame should be already rendered and ready to go. But instead it has just began. On iOS touch events seem to be delivered within few milliseconds of the display link callback so there should be enough time.

You can pause the "bad" video to see that during scrolling Flutter lags behind native by one frame exactly.

The expected video is with quick and dirty engine modification that forces BeginFrame immediately on input event.

The way vsync is implemented in Flutter might need some work. It should make sure that repaints are synchronized with display updates, but it shouldn't be causing additional latency.

@knopp
Copy link
Member Author

knopp commented Aug 28, 2022

To clarify - in first video there are frames like this:

Screenshot 2022-08-28 at 14 16 13

where the flutter scroll view doesn't keep up with UITableView (on the right) because is always one frame behind. The video on the right stays aligned at all times.

@knopp knopp added engine flutter/engine repository. See also e: labels. a: fidelity Matching the OEM platforms better labels Aug 28, 2022
@knopp
Copy link
Member Author

knopp commented Aug 28, 2022

cc @iskakaushik

@theniceboy
Copy link
Contributor

https://www.youtube.com/watch?v=N66MdEDHh2Q

This is a slo-mo video recorded that can demonstrate this issue.

Up top is the Wonderous app, and down below is a swift app.

@pedromassango
Copy link
Member

pedromassango commented Sep 5, 2022

@knopp were you able to reproduce this on Android? Seems iOS specific, can't reproduce on Android Emulator so far.

@pedromassango pedromassango added the platform-ios iOS applications specifically label Sep 5, 2022
@chinmaygarde chinmaygarde added the P2 Important issues not at the top of the work list label Sep 6, 2022
@MobileMon

This comment was marked as off-topic.

@jmagman
Copy link
Member

jmagman commented Sep 7, 2022

cc @cyanglaz

@cyanglaz cyanglaz self-assigned this Sep 7, 2022
@Hixie
Copy link
Contributor

Hixie commented Oct 4, 2022

@knopp btw please don't hesitate to land your test app in https://github.com/flutter/platform_tests if you want to. Collecting test apps like this is what that repo was made for.

@cyanglaz
Copy link
Contributor

I'm not currently working on this so I'll un-assign myself. I might circle back to this eventually.
@knopp Do you mind to open a draft PR with your engine modification that results the right video?

@cyanglaz cyanglaz removed their assignment Oct 25, 2022
@alidcast
Copy link

@cyanglaz did you see this as being reasonably in-reach to resolve?

There's comments about Flutter being in an "uncanny valley" - close to native, yet slightly different in an uncanny way. Outside of just saying "performance" or "jank" I couldn't identify why scrolling feels off in every flutter app I tried. So I find relief at finding issues like this since they identify why that's the case, and fixing these issues overtime make true native experience feel feasible! 🤞

If I may suggest, this feels like a higher priority issue as scrolling is a major interaction in any app.

@mark8044

This comment was marked as duplicate.

@yashwant1999
Copy link

@knopp do you have any workaround regarding this or any PR or may any sample repo with your modification. I wish I could help but due to limited knowledge, i can't. And this is first think i always notice when i run my app . As a perfectionist, you foolishly try to split flutter app and other app side by side and try to compare but there is always a feeling of something being "off" but can't figure out. i tried all best performance pratice but i think this is the issue if i am not wrong.

@Juliotati
Copy link

@yashwant1999 meanwhile the requested PR is not here, I can share something that might be related to this which I saw back them.

double? get dragStartDistanceMotionThreshold => parent?.dragStartDistanceMotionThreshold;

double get dragStartDistanceMotionThreshold => 3.5;

@knopp
Copy link
Member Author

knopp commented Jan 2, 2023

@Juliotati, this particular issue needs to be fixed in the engine, not framework.

@movaid7
Copy link

movaid7 commented Jan 2, 2023

@knopp is this behaviour present when using an Impeller runtime?

@kamami

This comment was marked as duplicate.

@jessetabak
Copy link

I’ve had this experience for years, scrolling always feels off, muddy, laggy. It’s the main reason I never got into flutter. I need snappy scrolling 😉

@cyanglaz
Copy link
Contributor

@knopp I tried to repro but I'm seeing a different behavior. The scrolling acceleration seems different between iOS and Flutter. Could you post your workaround so I can try it too?

@knopp
Copy link
Member Author

knopp commented Feb 10, 2023

@knopp I tried to repro but I'm seeing a different behavior. The scrolling acceleration seems different between iOS and Flutter. Could you post your workaround so I can try it too?

This is not about scroll physics. This is just about the tracking phase (following finger while the finger is down). The physics only comes into play after lift (and is indeed slightly different but that's not the point here).

I don't have the changes anymore, it was just a quick and dirty hack to trigger beginning frame immediately after event (instead of scheduling vsync), but i didn't pus it anywhere.

@theniceboy
Copy link
Contributor

theniceboy commented Feb 28, 2023

Seeing this behavior on iPad scrolling with the Apple Pencil. You can see that the iOS recognizes the pencil first and triggers the scribble API (which is a Flutter bug), and a few frames after that Flutter would react.

I'm on Flutter 3.7.5

Upload.from.GitHub.for.iOS.MOV

Video recorded at 240fps. Sorry the video is short, it helps if you scrub through the timeline

@aytunch
Copy link

aytunch commented Feb 28, 2023

@ slowmotionbot

Here is your slowed down video with 5x
https://user-images.githubusercontent.com/6442915/221829162-1fdeb20c-7c08-45cf-b52c-83e552f89feb.mp4

@bobmoff
Copy link

bobmoff commented Jun 5, 2023

@knopp Is there any chance that you could redo that change you made and share it with us so that we might experiment and perhaps make an example repo for the Flutter team to try?

If you dont have time, perhaps you could just point us in the right direction? Any help is appreciated 😁.

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@smith558

This comment was marked as duplicate.

@huykgit98

This comment was marked as duplicate.

@qfournetworks
Copy link

qfournetworks commented Jun 28, 2024

Maybe helpful additional info: This issue seems to only apply to IOS running 60hz.

I'll look further into resolving this issue soon.

Some of our customers noticed this issue running our app on "60hz IPhones"

@knopp
Copy link
Member Author

knopp commented Jun 30, 2024

Couldn't it be just that is much less obvious at 120Hz? As far as I can tell the frame cycle should be the same, the latency should be still present just shorter in absolute numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: fidelity Matching the OEM platforms better engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

No branches or pull requests