perf(linter/import/no-cycle): skip the graph walk for acyclic modules #24963
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
connorshea
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_oncewalks the module graph once per direct import, and each walk explores the module's whole reachable subgraph before concluding "no cycle". Onvscode/srcthat 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:
should_traverse_modulefilter;max_depth, so its reachable set is a strict superset;Arcidentity, 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 smallmax_depththe 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-cycleas 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
main, 1,566 on this branch, byte-identical after sorting by(filename, labels, message, code).oxc_lintertest suite passes with no snapshot changes;cargo clippy --all-features -D warningsclean.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_modulesinto a pre-sorted immutable slice after linking would remove the per-edgeCompactStrclone and the per-node sort for those, but it touchesModuleRecord'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