Skip to content

Using ComputeTaskPool for a par_for_each query only uses half of available logical cores #1907

@MJohnson459

Description

@MJohnson459

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.

use bevy::tasks::ComputeTaskPool;
pub fn how_many_threads(pool: Res<ComputeTaskPool>, 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:

impl Default for DefaultTaskPoolOptions {

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AppBevy apps and pluginsC-BugAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions