perf(linter/import/no-cycle): reduce allocations #24961
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.55) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 560 lines diff across 7 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.379
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #24961"
general
weight: 0.35
connorshea
AI Disclosure: This was generated using Claude Code w/ Opus 5. I have reviewed it to the best of my ability and confirmed to the best of my ability that it does not break anything (at least not obviously) in the vscode codebase. But it probably needs further testing. If we want to close this PR and have someone else push this change forward, that'd be fine by me.
What this shows
import/no-cyclewalks the module graph once per direct import of every linted file, and nearlyevery node and edge of that walk allocates. On the vscode codebase (
src, 7,368 files) the ruleaccounts for 330M of oxlint's 383M heap allocations and ~86% of total rule time when it is
enabled.
Removing four hot-path allocations cuts that substantially.
Changes
should_traverse_modulecollected twoVecs per graph edge, only to testis_empty()andall(is_type). Now iterates with an early break.Vecper visited node. Now staged on one scratch stackshared by the whole walk; each frame owns
scratch[start..end]and truncates on the way out.Entries are moved out with
mem::replacerather than cloned.traversedset cloned aPathBufper visited node. Now keyed onArcpointer identity.PathBufper node entered. Now holds anArc<ModuleRecord>.std::env::current_dir()is resolved once per file rather than once per emitted diagnostic.Measurements
vscode
src, 7,368 files, all 785 non-type-aware rules enabled, release build withmimalloc:| metric | before | after | delta |
| ----------- | ------ | ------ | ---------- |
| allocations | 383.4M | 134.1M | -65.0% |
| bytes | 29.0GB | 12.5GB | -57.0% |
| wall clock | 3635ms | 2719ms | -25.2% |
| CPU time | 56.8s | 42.5s | -25.2% |
With only
import/no-cycleenabled, allocations go from 332.6M to 83.4M (-74.9%).Wall clock and CPU are paired interleaved measurements (alternating binary order to cancel thermal
drift), n=20, t=30.9 and t=71.3, patched build faster in 20/20 runs. These are measured from the
exact commit on this branch, not from a prototype. Allocation counts come from a
counting global allocator, 2-3 reps, run-to-run spread <0.001%.
Correctness so far
no-cyclediagnostics on vscode are byte-identical before and after when sorted.import::andoxc/no_barrel_fileunit tests pass. Clippy is clean.Open questions
1. Is the
Arcpointer key acceptable? It is equivalent to keying on the path only becauselinking resolves every
loaded_modulesedge tomodules_by_path[path].last(). That is truetoday, but it is implicit, and it sits next to a
TODO: revise how to store multiple sections in. I added aloaded_modules
debug_assertthat re-checks pointer identity against path identity,but interning paths to a
u32id would remove the coupling entirely. Preference?2.
Arc<PathBuf>was tried and is worse. Changingresolved_absolute_pathtoArc<PathBuf>reaches the same allocation count with exact path semantics, but benchmarks slower than the
unpatched baseline* (3027ms vs 2893ms) — cloning an
Arcshared across 18 rayon threads turns amalloc into a contended atomic increment. Recording this so nobody repeats it.
3. The algorithmic cost is untouched.
no-cycleis still O(files x graph size), with a freshtraversedset per direct import. The remaining 83M allocations are mostlyCompactStrspecifier clones in the scratch
extend. Makingloaded_modulesa pre-sorted immutable listafter graph construction would let the walk borrow instead of clone, and is probably the larger
remaining win. Worth pursuing?
Not done