prepare_window hangs for long frame hitches when experiencing background CPU load
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
10.1
## Relevant system information
```ignore
`AdapterInfo { name: "NVIDIA GeForce GTX 1080 Ti", vendor: 4318, device: 6918, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "516.94", backend: Vulkan }`
`SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz", core_count: "4", memory: "32.0 GiB" }`
```
## What you did
Ran this code with Chrome or some other task in the background, creating periods of higher background CPU usage.
```rust
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Hitch".to_string(),
..Default::default()
}),
..Default::default()
}))
.insert_resource(FrameTimer::new())
.add_system(frame_system)
.run();
}
#[derive(Resource)]
struct FrameTimer {
last: std::time::Instant,
}
impl FrameTimer {
fn new() -> Self {
Self {
last: std::time::Instant::now(),
}
}
}
fn frame_system(mut timer: ResMut) {
let now = std::time::Instant::now();
let duration = now - timer.last;
if duration.as_millis() > 30 {
println!("{}", duration.as_millis());
}
timer.last = now;
}
```
## What went wrong
At higher CPU loads, bevy will get stuck in long hitches -- tracy shows this hang occurring in window::prepare_window.

## Additional information
This seems like there's some sort of thread contention issue. There's an element of "well, duh" to this where certainly performance will degrade as CPU usage rises, but this is a pretty drastic hitch rather than a gradual framerate drop. I haven't observed behavior like this in other engines, so I'm wondering if there's some trick here to avoiding this issue and presenting a smoother experience without such a frame time contrast?
Contributor guide
Assessment
This issue has not been assessed yet.