perf(linter): avoid per-call heap allocations in jest and unicorn helpers #25210
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 423 lines diff across 5 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.362
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #25210"
general
weight: 0.35
connorshea
This was generated with Claude Code, Opus 5. I have reviewed and tested it for correctness.
---
Four small allocation removals in linter helpers that run on hot paths. No behaviour change — these are pure
Vec→SmallVec/borrowed-iterator swaps.unicorn::does_expr_match_any_path— the member-chain segment buffer becomesSmallVec<[&str; 4]>. This is hotter than it looks:prefer_object_from_entriescalls it on every single-argument call expression.parse_jest_fn::ParsedExpectFnCall::modifiers— returnsSmallVec<[_; 2]>. Anexpectchain carries at most.not/.resolves/.rejects. All 14 call sites are unchanged; the one that passes the result into a&[_]parameter works via deref coercion.jest::get_node_name_vec— returnsSmallVec<[Cow<str>; 4]>.jest::collect_ids_referenced_to_import— returns the borrowed iterator instead of collecting it into aVec. The backing slice comes fromresolved_references(), which outlives the closure.Measurements
Built two release binaries (this branch vs its merge-base) with a counting global allocator, then measured
rule_attributable = total(rules on) − total(parse-only)at--threads=1over 18 unicorn/jest/vitest rules. Each cell was measured twice and asserted equal; parse-only counts were byte-identical between the two binaries, so the subtraction is sound.| corpus | allocations | bytes |
|---|---|---|
| grafana (8,510 files) | 6,321,943 → 4,862,436 — −1,459,507 (−23.1%) | 664.8 MB → 533.5 MB (−19.7%) |
| getsentry/sentry (
static/app) | 4,028,919 → 3,043,615 — −985,304 (−24.5%) | 424.2 MB → 336.1 MB (−20.8%) || synthetic unicorn fixture | −60,000 (−14.8%) | −3.8 MB (−12.9%) |
| synthetic jest fixture | −810,270 (−19.7%) | −72.7 MB (−17.3%) |
Note that oxc's arena allocations bypass the counting allocator (one
mallocper arena chunk), so these counts isolate exactly the non-arenaVecchurn these changes target.Inline capacities are correctly sized. On the unicorn fixture the saving is exactly 64.0 bytes per eliminated allocation — precisely a
Vec<&str>buffer at capacity 4 — so every call avoided the heap with zero spills. For the jest helpers, bytes-per-eliminated-allocation is 89.9 (grafana), 89.3 (sentry) and 89.7 (fixture), three independent corpora agreeing to within 0.7%, which says real-world test code hits the same size distribution as the fixture. That's strong evidence rather than the direct zero-spill proof I have for the unicorn path.Caveat on wall clock. Released oxlint builds with
--features allocator(mimalloc), while the instrumented binaries used the system allocator. Allocation counts are allocator-independent, but mimalloc services small allocations much more cheaply, so the time saved in the shipped binary is smaller than a 23% allocation reduction might imply. I'm deliberately not attaching a wall-clock number: these changes sit below the noise floor of end-to-end timing, which is why I measured allocations directly.Correctness
cargo test -p oxc_linter— 1,218 passedmainon both real corpora (30,169 on grafana, 16,266 on sentry), compared as sorted multisets without--silentjust fmtandcargo clippy -p oxc_linter --all-featuresclean🤖 Generated with Claude Code