Skip to content

perf(roadmap): stage and implement build the cycle graph per item #6516

Closed

Description

@dan-petty

Problem Description

Since #6449 (PR #6505, 494de4f), open_dependency (src/devops_cli/roadmap/dependencies.py:36-52) builds the full dependency graph of all open items each time it finds an open dependency: DependencyGraph.of(items).cycle_of(item.number) at line 49. The stage judge (src/devops_cli/roadmap/stage/stage.py:774) and the implement judge (src/devops_cli/roadmap/implement/implement.py:382) call it once for each item that they judge. Refine builds the graph once for each round and passes it in, but stage and implement do not.

Measured on 2026-11-20, read only:

  • One build over the 798 open items takes 3.3 s (two markdown parses of each body).
  • 27 Ready items have an open #N dependency today.
  • One devops roadmap explain 4814 called DependencyGraph.of 28 times, 93.7 s in total, of 321 s.

The Service stage round runs the same selection, so each stage round spends about 90 s more CPU. The cost grows with the number of Ready items that have a dependency times the number of open items.

Also, the path search _path_back (src/devops_cli/roadmap/refine/refine.py:1347) is a last-in-first-out search that copies the path at each step. It does not give the shortest cycle: for #1 → [#2, #3], #2 → #1, #3 → #4 → #1 it names #1 → #3 → #4 → #1. A ring of 500 items takes 0.52 s, and a ring of 20,000 items did not end in 3 minutes. Live cycles have 2 to 4 items today, so this part is minor.

Reproduction Steps

  1. Wrap DependencyGraph.of with a counter and a timer.
  2. Run uv run devops roadmap explain 4814.
  3. The counter shows 28 calls and 93.7 s.

Expected vs Actual Behavior

  • Expected: each selection (stage, implement, explain) builds the graph once and reuses it for each item, as refine does.
  • Actual: each judged item with an open dependency builds the full graph again.

Environment Diagnostics

devops-cli at main 494de4f (2026-11-20), after #6505.

Dependencies

None.

Acceptance Criteria

  • A test: a stage selection over several items that have open dependencies builds the graph once.
  • The same for the implement selection.
  • The cycle path is a shortest cycle through the item (breadth-first search), and a long ring does not copy the path at each step.

See #6449.

Alternatives check of 2026-11-20: not-applicable.
Class: perf, no search.
Tool: none found.

Proposed design

Problem statement

Stage, implement and explain rebuild the full dependency graph for each judged item that has an open dependency. One build over 798 open items takes 3.3 s, and one explain run built the graph 28 times for 93.7 s. The refine path search copies the path at each step and returns a longer cycle. The change builds the graph once per selection and uses breadth-first search for the shortest cycle.

Acceptance criteria

Requirement: Stage builds one graph

The stage selection SHALL build the dependency graph at most once for all judged items that have an open dependency.

Scenario: Two stage items with open dependencies

  • WHEN A test wraps DependencyGraph.of with a counter and runs the stage selection over two items that each have an open dependency.
  • THEN The counter is 1.

Requirement: Implement builds one graph

The implement selection SHALL build the dependency graph at most once for all judged items that have an open dependency.

Scenario: Two implement items with open dependencies

  • WHEN A test wraps DependencyGraph.of with a counter and runs the implement selection over two items that each have an open dependency.
  • THEN The counter is 1.

Requirement: Explain builds one graph

The explain selection SHALL build the dependency graph at most once for all items that it explains with an open dependency.

Scenario: Two explain items with open dependencies

  • WHEN A test wraps DependencyGraph.of with a counter and runs the explain selection over two items that each have an open dependency.
  • THEN The counter is 1.

Requirement: No graph without an open dependency

A selection SHALL build no dependency graph when no judged item has an open dependency.

Scenario: Stage items with closed dependencies

  • WHEN A test wraps DependencyGraph.of with a counter and runs the stage selection over items whose dependencies are closed.
  • THEN The counter is 0.

Requirement: Shortest cycle

The path search SHALL return a shortest cycle through the start item.

Scenario: Two cycles from one item

  • WHEN A test calls _path_back with edges 1 to [2, 3], 2 to [1], 3 to [4] and 4 to [1], and start 1.
  • THEN The result is (1, 2, 1).

Requirement: Long ring

The path search SHALL find the cycle in a 20,000-item ring in under 5 seconds.

Scenario: Twenty-thousand-item ring

  • WHEN A test calls _path_back on a ring of 20,000 items and measures the elapsed time.
  • THEN The result is a cycle of 20,001 entries and the elapsed time is under 5 seconds.

Existing Tool Considered

The alternatives check in the issue body records not-applicable and names no tool. The change adopts no library for this internal performance fix; it edits the existing DependencyGraph and _path_back in src/devops_cli/roadmap/dependencies.py and src/devops_cli/roadmap/refine/refine.py. No replacement library is built, so no build-versus-tool token or elapsed-time cost applies.

Key questions

  • How should stage, implement and explain reuse the dependency graph?: Build one lazy graph holder per selection. It calls DependencyGraph.of on the first cycle lookup and returns the same graph for later items. Pass the holder to open_dependency for each judged item. (best practice) [sources: src/devops_cli/roadmap/dependencies.py:36, src/devops_cli/roadmap/dependencies.py:49, src/devops_cli/roadmap/stage/stage.py:774, src/devops_cli/roadmap/implement/implement.py:382]
    • Chosen: Lazy graph holder per selection. It keeps one build per selection and builds no graph when no item has an open dependency.
    • Rejected: Eager graph per selection. It adds a 3.3 s build to a selection that has no open dependency.
    • Rejected: Global memoization of DependencyGraph.of. The cache key is fragile and the cache keeps item graphs alive after the selection.
  • Which algorithm should _path_back use to find the shortest cycle?: Use breadth-first search from the start item with a parent map. Reconstruct the cycle when a neighbor is the start item. (best practice) [sources: src/devops_cli/roadmap/refine/refine.py:1347, src/devops_cli/roadmap/refine/refine.py:1317]
    • Chosen: Breadth-first search with parent map. It returns a shortest cycle in O(V+E) time and stores one parent per node.
    • Rejected: Current last-in-first-out search with path copies. It returns a longer cycle and copies the path at each step.
    • Rejected: Floyd-Warshall. It computes all-pairs shortest paths in O(V^3) time and is too slow for a long ring.
  • Where does the repeated graph build happen today?: open_dependency calls DependencyGraph.of(items).cycle_of(item.number) after it finds an open dependency. Stage and implement each call open_dependency for each judged item. [sources: src/devops_cli/roadmap/dependencies.py:36, src/devops_cli/roadmap/dependencies.py:49, src/devops_cli/roadmap/stage/stage.py:774, src/devops_cli/roadmap/implement/implement.py:382]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/infra
    on Nov 20, 2026
  2. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. Each stage round wastes about 90 s of CPU and the cost grows with queue size, which is clear performance degradation. The regression commit 494de4f does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 with the label priority/p0-critical.
    • Related: fix(roadmap): name a dependency cycle instead of waiting #6449, which asks for a different change. Both work on dependency cycle detection in the roadmap, but #6449 adds the cycle check and this candidate fixes the per-item rebuild cost it introduced.
  3. added
    source/agent
    scope/roadmap
    status/new
    effort/medium
    value/high
    priority/p1-high
    on Nov 20, 2026
  4. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. added
    status/ready
    and removed
    status/new
    on Nov 20, 2026
  6. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 20, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 20, 2026
  9. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor
  10. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-20 17:44 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/roadmapsource/agenttype/infravalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions