Frame rate drop caused by high polling rate mouse
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy Version
0.13.1
## System Information
SystemInfo { os: "Windows 11 Home", kernel: "22631", cpu: "AMD Ryzen 9 7940HS w/ Radeon 780M Graphics", core_count: "8", memory: "15.2 GiB" }
AdapterInfo { name: "NVIDIA GeForce RTX 4060 Laptop GPU", vendor: 4318, device: 10464, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "536.45", backend: Vulkan }
## What Went Wrong
I have a mouse that allows me to adjust its polling rate. There are no issues when the mouse's polling rate is below 2000Hz. However, when I set the polling rate to 4000Hz, even in the simplest scenes, rapidly moving the mouse causes a significant drop in frame rate, with the maximum frame time increasing from around 10ms to about 80ms. [Minimal example](https://github.com/benkyoujouzu/bevy-high-polling-rate-mouse-problem)
1000Hz:
4000Hz:
## What You Did
Since I haven't encountered similar issues in Godot and some games, it likely isn't a problem with the performance of my computer.
I tried using `PresentMode::Fifo`, `PresentMode::Mailbox`, and `PresentMode::Immediate`, but the frame drops did not improve.
I attempted the method from [SDL#8756](https://github.com/libsdl-org/SDL/issues/8756) using GetRawInputBuffer to acquire raw mouse input in a dedicated thread [(my code)](https://github.com/benkyoujouzu/bevy-high-polling-rate-mouse-problem/tree/GetRawInputBuffer), yet there was still no improvement.
Tracing data shows a lot of `CursorMoved` events between two frames when using a 4000Hz polling rate. I tried commenting out the code handling `CursorMoved` in bevy_winit and setting `event_loop.listen_device_events(DeviceEvents::Never)`, but these did not solve the problem.
1000Hz:
4000Hz:
I suspect that some logic within bevy_winit or winit might be causing the stutter with high polling rate mice, but I haven't identified the cause. Do you have any idea?
Contributor guide
Research direction
Start by running the linked minimal example on Windows with 1000Hz and 4000Hz polling rates, then compare the tracing output and CursorMoved event volume. Inspect the bevy_winit CursorMoved handling and the related winit event-loop behavior; done means identifying the source of the frame-time increase and documenting or resolving it with a reproducible test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100