tauri-apps / wry

Cross-platform WebView library in Rust for Tauri.
Apache License 2.0
3.53k stars 262 forks source link

Stuttering in animations when moving the mouse. #618

Open aarchangel64 opened 2 years ago

aarchangel64 commented 2 years ago

Describe the bug When moving the mouse, animations will stutter (at least on Linux, I haven't tested this on MacOS or Windows). This does not happen in Epiphany, strangely enough, so I'm guessing it's an issue with Wry. Even stranger is that some things like HTML Canvas animations seem to not be affected (see videos attached below). Note that selecting any engine in the benchmark below leads to this behaviour, not just CSS Transitions.

Steps To Reproduce

  1. Edit the hello_world.rs example to go to this URL: https://greensock.com/js/speed.html (or any other CSS animation heavy page)
  2. Run cargo run --example hello_world --release
  3. Move the mouse and observe stutter.

Expected behavior No stuttering in CSS animations.

Screenshots Video of stutter: https://user-images.githubusercontent.com/13304815/174202243-c83d7427-4745-47be-8a57-d130b002ee7f.mp4

Video of Epiphany on the same page: https://user-images.githubusercontent.com/13304815/174202319-62524a3d-ce71-4328-873c-f24ac15cf3ed.mp4

Video of a HTML Canvas demo: https://user-images.githubusercontent.com/13304815/174202363-844eb264-0fe2-4d98-96b0-48fb85a136e7.mp4

Platform and Versions (please complete the following information): OS: Arch Linux Rustc: 1.61.0 (fe5b13d68 2022-05-18)

Would you assign yourself to resolve this bug?

Additional context Hardware: AMD Ryzen 3900X, Nvidia GTX 980ti, 32GB RAM.

wusyong commented 2 years ago

I think this is because we also catch many window events at the same time. Either ControlFlow::Poll or ControlFlow::Wait can't prevent this. Especially when they get the mouse position signal.

wusyong commented 2 years ago

Okay I disabled all catching cursor events and it no longer stuttering. I think #616 also suffer from this. We'll have to find the specific event that cause the trouble and maybe add options to toggle them.

wusyong commented 2 years ago

Sorry I just found previous stuttering is from my driver. After fixing it I couldn't distinguish it easily. @Cosmic-Goat Could you change to ControlFlow::Poll and see if the stuttering still exists?

aarchangel64 commented 2 years ago

@wusyong I just tried this on another machine, and I don't have any stuttering! (with both ControlFlow::Poll and ControlFlow::Wait) So I'm guessing it was also a driver issue for me - what did you do to fix your driver?

If it helps: the original machine with stuttering uses an NVIDIA 980ti, this other machine with no stuttering has an Intel Iris XE GPU. Both are running Arch Linux.

aarchangel64 commented 2 years ago

I am travelling right now, so I cannot test on my main computer with the stuttering for another few days. I believe I had tried ControlFlow::Poll however, and it made no difference. I will try again once I am back home.

wusyong commented 2 years ago

@Cosmic-Goat I just tried to remove and update latest driver. Nvidia is always painful to debug with. I suspect it's because some EGL issues which gtk also uses it.

aarchangel64 commented 2 years ago

@wusyong I'm on the latest Nvidia driver (515.48), and I still have stuttering. I have no stuttering in Epiphany, so I don't think it's an issue with EGL / GTK.

ControlFlow::Poll didn't make a difference. I've tried a few WMs (i3, AwesomeWM, Hypr) and they all have the issue, so it's not something WM specific. I also tried disabling Vsync and my compositor (Picom) and that didn't help either.

How can I disable catching all cursor events? Maybe I can try that and see if it helps. Also, thank you for taking time to help with this issue!

wusyong commented 2 years ago

@Cosmic-Goat Can you try this example? This only has a few setting with bare webkit2gtk-rs.

aarchangel64 commented 2 years ago

@Cosmic-Goat Can you try this example? This only has a few setting with bare webkit2gtk-rs.

@wusyong Just tried it, and there is no stuttering on that example. So there must be a bug somewhere in Wry, correct? Apologies for such a difficult issue to debug!

Also, upgrading to wry 0.19 / tao 0.12 did not help, if that matters.

wusyong commented 2 years ago

I'm working on DeviceEventFilter on Windows at the moment. I think this can also apply to Linux. https://github.com/tauri-apps/tao/pull/465

wusyong commented 2 years ago

@Cosmic-Goat I just found there's no device event on Linux actually, but the window will still send cursor events and others. I tried to make a branch to disable them. Could you test it? Because our other devs and I couldn't see the stuttering on that site. It might be better if there are other samples that are easier to distinguish. https://github.com/tauri-apps/wry/tree/disable-wireup