Skip to content

Commit

Permalink
for disconnected, use Vec instead of HashSet to reduce insert overhead (
Browse files Browse the repository at this point in the history
bevyengine#7744)

# Objective

- Improve `Schedule::initialize` performance

## Solution

- replace `disconnected`'s type from HashSet to Vec in `check_graph`
  • Loading branch information
shuoli84 committed Feb 19, 2023
1 parent bd54c4d commit d46427b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/schedule/graph_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub(crate) struct CheckGraphResults<V> {
/// Pairs of nodes that have a path connecting them.
pub(crate) connected: HashSet<(V, V)>,
/// Pairs of nodes that don't have a path connecting them.
pub(crate) disconnected: HashSet<(V, V)>,
pub(crate) disconnected: Vec<(V, V)>,
/// Edges that are redundant because a longer path exists.
pub(crate) transitive_edges: Vec<(V, V)>,
/// Variant of the graph with no transitive edges.
Expand All @@ -151,7 +151,7 @@ impl<V: NodeTrait + Debug> Default for CheckGraphResults<V> {
Self {
reachable: FixedBitSet::new(),
connected: HashSet::new(),
disconnected: HashSet::new(),
disconnected: Vec::new(),
transitive_edges: Vec::new(),
transitive_reduction: DiGraphMap::new(),
transitive_closure: DiGraphMap::new(),
Expand Down Expand Up @@ -198,7 +198,7 @@ where

let mut reachable = FixedBitSet::with_capacity(n * n);
let mut connected = HashSet::new();
let mut disconnected = HashSet::new();
let mut disconnected = Vec::new();

let mut transitive_edges = Vec::new();
let mut transitive_reduction = DiGraphMap::<V, ()>::new();
Expand Down Expand Up @@ -255,7 +255,7 @@ where
if reachable[index] {
connected.insert(pair);
} else {
disconnected.insert(pair);
disconnected.push(pair);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ impl ScheduleGraph {

// check for conflicts
let mut conflicting_systems = Vec::new();
for &(a, b) in flat_results.disconnected.iter() {
for &(a, b) in &flat_results.disconnected {
if self.ambiguous_with_flattened.contains_edge(a, b)
|| self.ambiguous_with_all.contains(&a)
|| self.ambiguous_with_all.contains(&b)
Expand Down

0 comments on commit d46427b

Please sign in to comment.