Skip to content

Conversation

@ItsDoot
Copy link
Contributor

@ItsDoot ItsDoot commented Nov 12, 2025

Objective

This is the final mile of cleanup I want to do for ScheduleGraph's implementation surface for now, I'll be focusing on other schedule bits after.

Solution

  • Upgraded and exposed Dag<N> as a fully-fledged directed acyclic graph type.
    • The validity of the cached topological order is now tracked by a dirty flag. All modifications to the graph (via DerefMut or Dag::graph_mut) cause the DAG to be marked as dirty.
    • Added Dag::toposort: if the DAG is dirty, computes topological order, caches it, and marks the DAG as clean. If already clean, returns the cached topological order. We now also reuse the previous toposort Vec allocation.
    • Added Dag::get_toposort: can be used to access the topological order with &self, with the stipulation that it returns an Option, and None if the DAG is dirty.
    • Replaced check_graph with Dag::analyze, and made it publicly accessible.
    • Added Dag::remove_redundant_edges, which uses the output of Dag::analyze.
  • Renamed CheckGraphResults to DagAnalysis.
    • Added DagAnalysis::check_for_redundant_edges, replacing ScheduleGraph::optionally_check_hierarchy_conflicts.
    • Added DagAnalysis::check_for_cross_dependencies, replacing ScheduleGraph::check_for_cross_dependencies. It now takes two full DagAnalysis for comparison.
    • Added DagAnalysis::check_for_cross_intersection, replacing ScheduleGraph::check_order_but_intersect.
  • Added DagGroups to encapsulate the HashMap<SystemSetKey, Vec<SystemKey>> with additional capabilities:
    • DagGroups::flatten and DagGroups::flatten_undirected handle the graph reduction operations previously performed by functions on ScheduleGraph.
  • Added ConflictingSystems to encapsulate Vec<(SystemKey, SystemKey, ComponentId)> with additional capabilities and type safety.

See the included migration guide for breaking changes.

Testing

  • Ran examples

Future work

  • Consider replacing HashSet<SystemKey> with a FixedBitSet-like type for better performance.

- Moved some functions to `CheckGraphResults` which don't make use of `ScheduleGraph` internals.
- Encapsulated conflicting systems into its own struct and moved related functions off of `ScheduleGraph`.
@ItsDoot ItsDoot added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Nov 12, 2025
@hymm hymm self-requested a review November 12, 2025 23:16
@ItsDoot ItsDoot added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Nov 13, 2025
@alice-i-cecile alice-i-cecile self-requested a review November 14, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant