perf(orchestration): cache forward adjacency in CascadeDetector#3114
Merged
perf(orchestration): cache forward adjacency in CascadeDetector#3114
Conversation
Add a lazily-built `forward_adjacency: Option<Vec<Vec<TaskId>>>` field to `CascadeDetector`. `ensure_adjacency` builds the dense index once per DAG lifetime and is invalidated exclusively in `reset()`, which is called from `inject_tasks` — the only production mutation path. `descendant_count` (called once per task per tick in `deprioritized_tasks` when cascade routing is active) no longer rebuilds a `HashMap` on every invocation. For diamond/fan-in DAGs the per-tick cost drops from O(K*(N+E)) to O(N*R*D) where D is the subtree size. Public methods `is_cascading`, `deprioritized_tasks`, and `evaluate_abort` become `&mut self` to carry the cache. A `#[cfg(test)]` accessor `forward_adjacency_is_cached` mirrors the existing `region_health` pattern. Closes #3094
ea1472c to
d4e869c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
forward_adjacency: Option<Vec<Vec<TaskId>>>cache toCascadeDetectordescendant_count(called per-task per-tick indeprioritized_tasks) no longer rebuilds aHashMapon every invocation — the dense index is built once per DAG lifetime and invalidated inreset()is_cascading,deprioritized_tasks, andevaluate_abortbecome&mut self; two scheduler call-sites updatedChanges
crates/zeph-orchestration/src/cascade.rs— cache field,ensure_adjacency,reset()invalidation, accessor, doc invariantcrates/zeph-orchestration/src/scheduler.rs—ref→ref mutat two call-sites, pre-binding borrow fix at :1457CHANGELOG.md—[Unreleased]Performance entryTest plan
cargo +nightly fmt --check— cleancargo clippy --workspace -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --lib --bins— 8175/8175 passreset()Closes #3094