Skip to content

High CPU overhead when using ParallelExecutor in a minimal throttled example #4718

@maun

Description

@maun

Bevy version

0.8-dev main aced6af

Operating system & version

macOS 12.3.1

What you did

Used minimal example:

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_system(sleep_system)
        .run();
}

fn sleep_system() {
    std::thread::sleep(std::time::Duration::from_millis(15));
}

and measured CPU usage with top / Activity Monitor.
The app was started using cargo run --release.

What you expected to happen

Running with close to 0% CPU usage.

What actually happened

CPU usage of 10-15%

Additional information

Using SingleThreadedExecutor by hardcoding it in bevy_ecs

pub fn parallel() -> Self {
    // Self::new(Box::new(ParallelExecutor::default()))
    Self::new(Box::new(SingleThreadedExecutor::default()))
}

results in a CPU usage of about 0.3%.

Similar behaviour exists for an empty window without using the renderer feature and also in the breakout example. For the empty window the CPU usage was quite low, whereas in the breakout example the CPU usage dropped about >10% with the change, but was still unexpectedly high.

I recorded flame graphs, to get the interactive version download the svg and open them in a browser.

ParallelExecutor

flamegraph-multi

The call to std::thread::sleep is at the highest "tower" on the left, you can zoom in when using a local interactive svg.

SingleThreadedExecutor

flamegraph-single

The same test without the sleep system results in 150% CPU usage with the ParallelExecutor and close to 100% with the SingleThreadedExecutor .

Issue #1462 is probably related but was closed and is less specific.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-TasksTools for parallel and async workC-PerformanceA change motivated by improving speed, memory usage or compile times

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions