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

Rapid cursor movement causes frame loss #3689

Open
AuracleTech opened this issue May 8, 2024 · 3 comments
Open

Rapid cursor movement causes frame loss #3689

AuracleTech opened this issue May 8, 2024 · 3 comments
Labels
B - bug Dang, that shouldn't have happened DS - windows

Comments

@AuracleTech
Copy link

AuracleTech commented May 8, 2024

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

@AuracleTech AuracleTech added B - bug Dang, that shouldn't have happened DS - windows labels May 8, 2024
@AuracleTech AuracleTech changed the title Cursor causes frame loss Rapid cursor movement causes frame loss May 8, 2024
@AuracleTech
Copy link
Author

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.

@AuracleTech
Copy link
Author

AuracleTech commented May 11, 2024

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

@madsmtm
Copy link
Member

madsmtm commented May 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - windows
Development

No branches or pull requests

2 participants