std::thread::sleep sleeps for too long in ScheduleRunnerPlugin
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
master
## Operating system & version
Windows 10 - this issue may be isolated to Windows?
## What you did
Create and run an app with ScheduleRunnerPlugin and set the expected FPS to an arbitrary number.
```
fn main() {
App::build()
.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 20.0,
)))
.add_plugin(ScheduleRunnerPlugin::default())
.add_plugin(DiagnosticsPlugin)
.add_plugin(FrameTimeDiagnosticsPlugin)
.add_plugin(LogDiagnosticsPlugin::default())
.run();
}
```
## What you expected to happen
FPS should be almost exactly 20 FPS
## What actually happened
FPS hovers between 15 and 16 FPS
## Additional information
I swapped only the [`std::thread::sleep(delay)`](https://github.com/bevyengine/bevy/blob/bc4fe9b186db3f32eef38fc4241289df480fa949/crates/bevy_app/src/schedule_runner.rs#L98) with the [spin sleep](https://crates.io/crates/spin_sleep) crate's `spin_sleep::sleep(delay)` and get almost exactly 20 FPS as expected.
Contributor guide
Research direction
Start with crates/bevy_app/src/schedule_runner.rs around the std::thread::sleep(delay) call linked in the issue. Reproduce the ScheduleRunnerPlugin example on Windows at 20 FPS, then compare its timing with the reported spin_sleep behavior. Done means the configured frame rate is close to the expected rate without introducing regressions in the schedule runner tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100