--- title: Weak system ordering with chain_weak authors: ["@JMS55"] pull_requests: [25128] --- Ordering large groups of systems with `.chain()` is convenient, but it can be overly strict. If system set `X` is chained before system set `Y`, every system in `X` must finish before *any* system in `Y` can start, even when the systems involved never touch the same data. This often leaves worker threads idle while they wait for a handful of stragglers at the end of a system set, a pattern that shows up frequently in the render world. The new `chain_weak()`, `before_weak()`, and `after_weak()` functions provide a looser alternative. Like their regular counterparts, they request an ordering between successive elements, however that ordering is only kept between systems whose data accesses actually conflict. Systems that don't conflict are left unordered and may run in any order, including in parallel. ```rust schedule.configure_sets( ( ExtractCommands, PrepareMeshes, CreateViews, Specialize, PrepareViews, Queue, PhaseSort, Prepare, Render, Cleanup, PostCleanup, ) .chain_weak(), ); ``` When two weakly-ordered systems actually conflict on their data access, a normal ordering is kept between them, so the earlier one still runs first. Two systems that conflict only through a non-conflicting system between them in the chain stay ordered as well. Non-conflicting systems, however, are left free to run in any order and overlap for increased parallelism! Two kinds of system are treated as always conflicting, so their ordering is always kept: an earlier system that produces deferred effects such as `Commands` (so the later system observes them, with an `ApplyDeferred` sync point inserted as usual), and exclusive systems (which cannot overlap anything regardless). Because the scheduler can only see accesses it tracks, dependencies expressed through interior mutability on read-only accesses, global state, or other untracked methods are **not** respected. Use `chain_weak` only when your systems don't rely on such hidden ordering, otherwise stick with `chain`.