Skip to content

Commit d95df29

Browse files
committed
early return from multithreaded executor (#7521)
# Objective - There is a small perf cost for starting the multithreaded executor. ## Solution - We can skip that cost when there are zero systems in the schedule. Overall not a big perf boost unless there are a lot of empty schedules that are trying to run, but it is something. Below is a tracy trace of the run_fixed_update_schedule for many_foxes which has zero systems in it. Yellow is main and red is this pr. The time difference between the peaks of the humps is around 15us. ![image](https://user-images.githubusercontent.com/2180432/216884536-f3af8f5e-6224-4d0f-8fbd-67b0beb90baf.png)
1 parent e7e3b2c commit d95df29

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

crates/bevy_ecs/src/schedule/executor/multi_threaded.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ impl SystemExecutor for MultiThreadedExecutor {
145145
fn run(&mut self, schedule: &mut SystemSchedule, world: &mut World) {
146146
// reset counts
147147
let num_systems = schedule.systems.len();
148+
if num_systems == 0 {
149+
return;
150+
}
148151
self.num_running_systems = 0;
149152
self.num_completed_systems = 0;
150153
self.num_dependencies_remaining.clear();

0 commit comments

Comments
 (0)