← Back to Pull requests

perf(linter/import/no-cycle): skip the graph walk for acyclic modules #24963

Closed
unknown closed this pull request without merging on Jul 27, 2026 23:41 UTC
View on GitHub
unknown unknown commented on Jul 27, 2026 00:09 UTC
Author

Stacked on #24961 — this PR targets perf/no-cycle-allocations, so it shows only the one commit on top. Review #24961 first.

Where #24961 makes each graph walk cheaper, this one stops running almost all of them.

What

run_once walks the module graph once per direct import, and each walk explores the module's whole reachable subgraph before concluding "no cycle". On vscode/src that is ~81k walks producing 1,566 diagnostics, so over 98% of them are pure overhead.

A module is in a cycle if and only if some module reachable from it imports it back. So one traversal of that subgraph answers the question for every direct import at once. When it says no, skip all the walks.

Why it can't change what's reported

The prefilter only gates the walks — they still decide what is reported and reconstruct the cycle path for the diagnostic. It cannot skip a cycle a walk would have found:

  • it traverses the same edges under the same should_traverse_module filter;

  • it is unbounded where the walks are bounded by max_depth, so its reachable set is a strict superset;

  • it compares by resolved path, not Arc identity, matching what the walks report a cycle on — a file split into multiple sections has one record per section but one path.
  • It runs only under the default unbounded max_depth, where the walks cover the whole subgraph anyway and the prefilter replaces work rather than adding to it. With a small max_depth the walks are shallow enough that an unbounded prefilter could cost more than it saves, so behaviour there is exactly as before.

    Measurements

    vscode/src (7,327 files, ~81k direct imports), import/no-cycle as the only enabled rule, paired interleaved runs with order alternation, n=15.

    vs. the base branch (perf/no-cycle-allocations, this PR's diff alone)

    | | wall clock | rule allocations | rule bytes |
    | --- | --- | --- | --- |
    | before | 2242.1 ms | 81.7M | 5.85 GB |
    | after | 946.1 ms | 15.3M | 2.03 GB |
    | | −1296.1 ms (−58%) | −81% | −65% |

    Paired delta sd 24.1, t = +208, faster in 15/15 rounds.

    vs. main (the whole stack)

    | | wall clock | rule allocations | rule bytes |
    | --- | --- | --- | --- |
    | main | 3330.5 ms | 331.0M | 22.46 GB |
    | this PR | 966.3 ms | 15.3M | 2.02 GB |
    | | −2364.2 ms (−71%) | −95.4% (21.7×) | −91.0% (11.1×) |

    Paired delta sd 97.3, t = +94.1, faster in 15/15 rounds. Subtracting the parse-only baseline, rule-attributable time goes 3182 ms → 818 ms, 3.9× faster.

    In both cases a parse-only control run (same binaries, no rules) is flat — +0.3 ms, t = +0.29 vs main — so the delta is attributable to the rule and not to the harness. Allocation figures are likewise rule-attributable: total minus a parse-only run on the same binary, counted with a global allocator shim. The parse-only baselines across separately-built binaries agree to within 0.04%, which is what makes that subtraction meaningful.

    Correctness

  • 1,566 diagnostics on main, 1,566 on this branch, byte-identical after sorting by (filename, labels, message, code).

  • Full oxc_linter test suite passes with no snapshot changes; cargo clippy --all-features -D warnings clean.
  • What's left

    The remaining 15.3M allocations are concentrated in the minority of files that genuinely sit in a cycle — those are exactly the ones in the large SCC, with the biggest reachable closures, and they still run the full walks. Freezing loaded_modules into a pre-sorted immutable slice after linking would remove the per-edge CompactStr clone and the per-node sort for those, but it touches ModuleRecord's shape and the runtime's linking phase, so it belongs in a separate PR.

    ---

    AI disclosure: this change was written with Claude Code. I reviewed the implementation, the soundness argument, and ran the benchmarks and parity checks myself.

    🤖 Generated with Claude Code

    Diff: 490 lines (+367 / -123) across 6 files Reviewer: connorshea Review duration: 1411m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.47) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 490 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.371
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #24963"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%