rust-windowing / winit

Window handling library in pure Rust

Home Page:https://docs.rs/winit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rapid cursor movement causes frame loss

AuracleTech opened this issue · comments

commented

Description

Faster cursor moves, the less framerate

No render load :

  • no cursor movement : ~4500 draw/s
  • rapid cursor movement : ~300 draw/s

Heavy render load :

  • no cursor movement : ~20 draw/s
  • rapid cursor movement : ~5 draw/s

Tried this pull request for high polling rate fix, didn't work
Note that I do not even utilize inputs yet

my event loop source

Green = framerate with no cursor movement
Red = framerate with rapid cursor movements

image

Windows version

Microsoft Windows 11 Pro
Version	10.0.22631 Build 22631

Winit version

0.29.15

commented

Seems like a strange issue. When recording, the bug is less visible. Tried changing Razer Synapse between 125hz and 8000hz, losing frames mostly at 8000hz. When OBS records I only lose 3-4 frames at 8000hz. Thinking it might be a Windows problem rather than winit. Profiling needed for confirmation.

commented

Conclusion: This is a Microsoft Windows issue, even without using winit the issue persists...

flamegraph

Note : function name are cryptic because they aren't from rust but from the Windows OS itself

image

Windows performance analyzer

No cursor movement :

  • 33 000 Thread: CSwitch
  • almost zero QueueNullPostMessage
    image

Cursor movement :

  • 225 000 Thread: CSwitch
  • 4000 QueueNullPostMessage which are the same length as the Thread: CSwitch so they must be related somehow
    image

Hot spot can be found in winit/src/platform_impl/windows/event_loop.rs line ~460 where a loop iterates.
If you stopwatch, the whole loop takes 100 nanoseconds with the cursor at rest.
But with rapid cursor movements it ramps up to 50 to 150 milliseconds, this is a massive performance hit.

Temporary fix 1 : Reduce polling rate of cursor to 1000 Hz or under
Temporary fix 2 : Do not rely on WindowEvent::RedrawRequested or the event loop to render, also multithread the renderer

Hopefully this helps

polling rate of cursor

Actually, I remember reading a (very good) article about this before, probably from Hacker News or something, can't seem to find it now. But a quick Google search does indeed suggest that this is a more general problem on Windows.