Skip to content

Commit 4bc2f39

Browse files
james7132ProfLander
authored andcommitted
Use a bounded channel in the multithreaded executor (bevyengine#7829)
# Objective This is a follow-up to bevyengine#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 bevyengine#4919. ## Solution Use a bounded channel to avoid allocations on system completion. This shouldn't conflict with bevyengine#7745, as it's impossible for the scheduler to exceed the channel capacity, even if somehow every system completed at the same time.
1 parent 5c6f02b commit 4bc2f39

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ impl SystemExecutor for MultiThreadedExecutor {
121121
let sys_count = schedule.system_ids.len();
122122
let set_count = schedule.set_ids.len();
123123

124+
let (tx, rx) = async_channel::bounded(sys_count.max(1));
125+
126+
self.sender = tx;
127+
self.receiver = rx;
124128
self.evaluated_sets = FixedBitSet::with_capacity(set_count);
125129
self.ready_systems = FixedBitSet::with_capacity(sys_count);
126130
self.ready_systems_copy = FixedBitSet::with_capacity(sys_count);

0 commit comments

Comments
 (0)