winit
winit copied to clipboard
Rapid cursor movement causes frame loss
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
Green
= framerate with no cursor movement
Red
= framerate with rapid cursor movements
Windows version
Microsoft Windows 11 Pro
Version 10.0.22631 Build 22631
Winit version
0.29.15
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.
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
Windows performance analyzer
No cursor movement :
- 33 000
Thread: CSwitch
- almost zero
QueueNullPostMessage
Cursor movement :
- 225 000
Thread: CSwitch
- 4000
QueueNullPostMessage
which are the same length as theThread: CSwitch
so they must be related somehow
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.
I am closing this issue considering its a windows issue and there's nothing we can do except point fingers at @Microsoft
I read a related blog post about this today, see https://ph3at.github.io/posts/Windows-Input/