bevyengine / bevyengine/bevy

Input lag with vsync enabled due to limited polling rates

Open
#3,317 20 comments 13 reactions 0 assignees View on GitHub
A-Input A-Windowing C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Problem

@aevyrie has observed noticeable input lag in Bevy applications when vsync is enabled.

The most immediate source of this is quite obvious: we're only fetching the input state at the start of each frame, but are rendering is done at the end of the frame.

Input events appear to be moved into the Bevy app by the `winit` runner: https://github.com/bevyengine/bevy/blob/de8edd3165c379e05aabb38359b3f4b97f46540a/crates/bevy_winit/src/lib.rs#L221

At 60 fps, this means 16 ms of lag, which is noticeable for some applications: namely for precise cursor movement (FPS, GUI applications) and rhythm games.

## Possible solutions

- Poll more regularly (somewhat limited by the OS I believe)
- I suspect this could be done at the end of each stage
- Perhaps a dedicated input-polling thread architecture would help?
- Poll closer to rendering time

Either solution will involve some trickiness, as we must pierce the Bevy schedule in some fashion in order to insert fresh input events into the World at the right time, rather than merely at the beginning of each pass over the schedule.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.