Copy TaskPool resoures to subapps (#4792)
# Objective Fixes #4791. `ParallelExecutor` inserts a default `CompteTaskPool` if there isn't one stored as a resource, including when it runs on a different world. When spawning the render sub-app, the main world's `ComputeTaskPool` is not cloned and inserted into the render app's, which causes a second `ComputeTaskPool` with the default configuration to be spawned. This results in an excess number of threads being spawned. ## Solution Copy the task pools from the main world to the subapps upon creating them. ## Alternative An alternative to this would be to make the task pools global, as seen in #2250 or bevyengine/rfcs#54.
This commit is contained in:
parent
6a238377be
commit
a02c5ae819
@ -20,6 +20,7 @@ bevy_derive = { path = "../bevy_derive", version = "0.8.0-dev" }
|
|||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev", default-features = false }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev", default-features = false }
|
||||||
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", optional = true }
|
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", optional = true }
|
||||||
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
|
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
|
||||||
|
bevy_tasks = { path = "../bevy_tasks", version = "0.8.0-dev" }
|
||||||
|
|
||||||
# other
|
# other
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
|
@ -10,6 +10,7 @@ use bevy_ecs::{
|
|||||||
system::Resource,
|
system::Resource,
|
||||||
world::World,
|
world::World,
|
||||||
};
|
};
|
||||||
|
use bevy_tasks::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};
|
||||||
use bevy_utils::{tracing::debug, HashMap};
|
use bevy_utils::{tracing::debug, HashMap};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
@ -862,9 +863,18 @@ impl App {
|
|||||||
pub fn add_sub_app(
|
pub fn add_sub_app(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: impl AppLabel,
|
label: impl AppLabel,
|
||||||
app: App,
|
mut app: App,
|
||||||
sub_app_runner: impl Fn(&mut World, &mut App) + 'static,
|
sub_app_runner: impl Fn(&mut World, &mut App) + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
|
if let Some(pool) = self.world.get_resource::<ComputeTaskPool>() {
|
||||||
|
app.world.insert_resource(pool.clone());
|
||||||
|
}
|
||||||
|
if let Some(pool) = self.world.get_resource::<AsyncComputeTaskPool>() {
|
||||||
|
app.world.insert_resource(pool.clone());
|
||||||
|
}
|
||||||
|
if let Some(pool) = self.world.get_resource::<IoTaskPool>() {
|
||||||
|
app.world.insert_resource(pool.clone());
|
||||||
|
}
|
||||||
self.sub_apps.insert(
|
self.sub_apps.insert(
|
||||||
Box::new(label),
|
Box::new(label),
|
||||||
SubApp {
|
SubApp {
|
||||||
|
Loading…
Reference in New Issue
Block a user