Using ComputeTaskPool for a par_for_each query only uses half of available logical cores
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.5
## Operating system & version
Linux
## What you did
I have a CPU heavy task and running it as part of a query `par_for_each` loop in a `ComputeTaskPool` and only half of my cores are being utilised. I originally used an AsyncTaskPool but this has even fewer threads assigned.
```rust
use bevy::tasks::ComputeTaskPool;
pub fn how_many_threads(pool: Res, query: Query<(&DummyComponent)>) {
info!("TaskPool threads: {}", pool.thread_num());
info!("Available cores: {}", num_cpus::get());
query.par_for_each_mut(&pool, 1, |_dummy| {
// Will only run on
});
}
```
> TaskPool threads: 6
> Available cores: 12
I know why this happens but it was unexpected:
https://github.com/bevyengine/bevy/blob/75ae20dc4a11f04fb0aad62e2a92ffe2b974ea89/crates/bevy_core/src/task_pool_options.rs#L54
## What you expected to happen
When not using the `IoTaskPool` or `AsyncComputeTaskPool` I would expect the `ComputeTaskPool` to use all logical cores. Likewise I would expect the other pools to expand to optimally use the CPU available.
Alternatively, documentation should be updated to make clear what the current behaviour is and steps to create a new task pool.
## What actually happened
Only half of the available core were used.
Contributor guide
Assessment
This issue has not been assessed yet.