← Back to Pull requests

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

Closed
unknown closed this pull request without merging on Jul 28, 2026 10:02 UTC
View on GitHub
unknown unknown commented on Jul 27, 2026 23:33 UTC
Author

This is the change from #24963, but as its own PR to avoid dependency on the larger refactor PR it was targeted at. Benchmarks have been re-run to ensure that the info is correct, but I'm pretty confident in this change now.

AI Disclosure: Generated with Claude Code, Opus 5. Reviewed and tested manually be me.

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 78,760 walks producing 1,566 diagnostics, so 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,368 files, 81,512 direct imports, 78,760 walks — with import/no-cycle as the only enabled rule (number_of_rules: 1). Paired interleaved runs with per-round order alternation, n=15, --silent, release builds with --features allocator.

    Wall clock

    | | mean | sd |
    | --------------------- | --------- | -------- |
    | main | 3217.3 ms | 169.3 ms |
    | this PR | 1178.3 ms | 56.1 ms |
    | paired delta | −2038.9 ms | 127.6 ms |

    t = +61.9, faster in 15/15 paired rounds. Subtracting the parse-only baseline, rule-attributable time goes 3110.5 ms → 1073.3 ms, 2.9× faster.

    The parse-only control (same binaries, no rules enabled) is flat — 106.8 ms vs 105.0 ms, paired delta +1.8 ms, t = +0.49 — so the delta is attributable to the rule and not to binary layout or the harness.

    Allocations

    Counted with a global-allocator shim; rule-attributable = total minus a parse-only run on the same binary.

    | | allocations | bytes |
    | ------- | ----------- | -------- |
    | main | 331.0M | 22.52 GB |
    | this PR | 86.8M | 6.05 GB |
    | | −73.8% | −73.1% |

    Counts are stable to within 0.05% across repetitions, and the two parse-only baselines (separately built binaries) agree to 0.003%, which is what makes that subtraction meaningful.

    Correctness

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

  • Full oxc_linter test suite passes (1,175 tests) with no snapshot changes; cargo clippy -p oxc_linter --all-features --all-targets -D warnings is clean.
  • Cross-codebase parity

    Both binaries were also run over five TypeScript codebases, under the default options plus two variants chosen to stress what is most likely to break: ignoreTypes: false changes which edges should_traverse_module admits, so the prefilter has to apply the identical filter, and maxDepth: 5 disables the prefilter entirely.

    | codebase | files | config | main | this PR | identical |
    | --- | --- | --- | --- | --- | --- |
    | vscode | 11,674 | default | 2,789 | 2,789 | ✅ |
    | actualbudget/actual | 1,789 | default | 188 | 188 | ✅ |
    | actualbudget/actual | 1,789 | ignoreTypes: false | 591 | 591 | ✅ |
    | actualbudget/actual | 1,789 | maxDepth: 5 | 47 | 47 | ✅ |
    | storybook | 4,050 | default | 96 | 96 | ✅ |
    | storybook | 4,050 | ignoreTypes: false | 430 | 430 | ✅ |
    | storybook | 4,050 | maxDepth: 5 | 40 | 40 | ✅ |
    | rolldown | 6,411 | default | 77 | 77 | ✅ |
    | rolldown | 6,411 | ignoreTypes: false | 239 | 239 | ✅ |
    | rolldown | 6,411 | maxDepth: 5 | 73 | 73 | ✅ |
    | microsoft/TypeScript | 39,333 | default | 729 | 729 | ✅ |
    | microsoft/TypeScript | 39,333 | ignoreTypes: false | 729 | 729 | ✅ |
    | microsoft/TypeScript | 39,333 | maxDepth: 5 | 242 | 242 | ✅ |

    Counts are import(no-cycle) diagnostics. The comparison is stricter than the counts: in all 13 runs the entire diagnostic array is element-wise identical after sorting by (filename, labels, message, code) — including the 30,713 parse errors the TypeScript repo's test fixtures produce — so no diagnostic changed span or cycle path either. These are full repository checkouts, which is why vscode is 11,674 files here rather than the 7,368 measured above.

    Diff: 630 lines (+472 / -158) across 7 files Reviewer: connorshea Review duration: 629m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.55) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 630 lines diff across 7 files
    0.55
    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.386
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #25003"
    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: 55.4% (MEDIUM) · Higher = larger blast radius
    55.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: 23.9% · Safe to merge
    23.9%