Skip to content

Commit

Permalink
Use a bounded channel in the multithreaded executor (#7829)
Browse files Browse the repository at this point in the history
# Objective
This is a follow-up to #7745. An unbounded `async_channel`  occasionally allocates whenever it exceeds the capacity of the current buffer in it's internal linked list. This is avoidable.

This also used to be a bounded channel before stageless, which was introduced in #4919.

## Solution
Use a bounded channel to avoid allocations on system completion.

This shouldn't conflict with #7745, as it's impossible for the scheduler to exceed the channel capacity, even if somehow every system completed at the same time.
  • Loading branch information
james7132 committed Feb 27, 2023
1 parent 3d3444b commit c785f28
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/schedule/executor/multi_threaded.rs
Expand Up @@ -121,6 +121,10 @@ impl SystemExecutor for MultiThreadedExecutor {
let sys_count = schedule.system_ids.len();
let set_count = schedule.set_ids.len();

let (tx, rx) = async_channel::bounded(sys_count.max(1));

self.sender = tx;
self.receiver = rx;
self.evaluated_sets = FixedBitSet::with_capacity(set_count);
self.ready_systems = FixedBitSet::with_capacity(sys_count);
self.ready_systems_copy = FixedBitSet::with_capacity(sys_count);
Expand Down

0 comments on commit c785f28

Please sign in to comment.