Skip to content

Commit d46427b

Browse files
committed
for disconnected, use Vec instead of HashSet to reduce insert overhead (#7744)
# Objective - Improve `Schedule::initialize` performance ## Solution - replace `disconnected`'s type from HashSet to Vec in `check_graph`
1 parent bd54c4d commit d46427b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

crates/bevy_ecs/src/schedule/graph_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub(crate) struct CheckGraphResults<V> {
135135
/// Pairs of nodes that have a path connecting them.
136136
pub(crate) connected: HashSet<(V, V)>,
137137
/// Pairs of nodes that don't have a path connecting them.
138-
pub(crate) disconnected: HashSet<(V, V)>,
138+
pub(crate) disconnected: Vec<(V, V)>,
139139
/// Edges that are redundant because a longer path exists.
140140
pub(crate) transitive_edges: Vec<(V, V)>,
141141
/// Variant of the graph with no transitive edges.
@@ -151,7 +151,7 @@ impl<V: NodeTrait + Debug> Default for CheckGraphResults<V> {
151151
Self {
152152
reachable: FixedBitSet::new(),
153153
connected: HashSet::new(),
154-
disconnected: HashSet::new(),
154+
disconnected: Vec::new(),
155155
transitive_edges: Vec::new(),
156156
transitive_reduction: DiGraphMap::new(),
157157
transitive_closure: DiGraphMap::new(),
@@ -198,7 +198,7 @@ where
198198

199199
let mut reachable = FixedBitSet::with_capacity(n * n);
200200
let mut connected = HashSet::new();
201-
let mut disconnected = HashSet::new();
201+
let mut disconnected = Vec::new();
202202

203203
let mut transitive_edges = Vec::new();
204204
let mut transitive_reduction = DiGraphMap::<V, ()>::new();
@@ -255,7 +255,7 @@ where
255255
if reachable[index] {
256256
connected.insert(pair);
257257
} else {
258-
disconnected.insert(pair);
258+
disconnected.push(pair);
259259
}
260260
}
261261
}

crates/bevy_ecs/src/schedule/schedule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ impl ScheduleGraph {
11261126

11271127
// check for conflicts
11281128
let mut conflicting_systems = Vec::new();
1129-
for &(a, b) in flat_results.disconnected.iter() {
1129+
for &(a, b) in &flat_results.disconnected {
11301130
if self.ambiguous_with_flattened.contains_edge(a, b)
11311131
|| self.ambiguous_with_all.contains(&a)
11321132
|| self.ambiguous_with_all.contains(&b)

0 commit comments

Comments
 (0)