← Back to Pull requests

perf(linter): avoid per-call heap allocations in jest and unicorn helpers #25210

Closed
unknown closed this pull request without merging on Aug 06, 2026 08:26 UTC
View on GitHub
unknown unknown commented on Aug 02, 2026 17:14 UTC
Author

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 becomes SmallVec<[&str; 4]>. This is hotter than it looks: prefer_object_from_entries calls it on every single-argument call expression.

  • parse_jest_fn::ParsedExpectFnCall::modifiers — returns SmallVec<[_; 2]>. An expect chain 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 — returns SmallVec<[Cow<str>; 4]>.

  • jest::collect_ids_referenced_to_import — returns the borrowed iterator instead of collecting it into a Vec. The backing slice comes from resolved_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=1 over 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 malloc per arena chunk), so these counts isolate exactly the non-arena Vec churn 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 passed

  • Diagnostics byte-identical to main on both real corpora (30,169 on grafana, 16,266 on sentry), compared as sorted multisets without --silent

  • just fmt and cargo clippy -p oxc_linter --all-features clean
  • 🤖 Generated with Claude Code

    Diff: 423 lines (+317 / -106) across 5 files Reviewer: connorshea Review duration: 5232m
    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
    0.50
    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%
    60%
    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.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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 50% (MEDIUM) · Higher = larger blast radius
    50%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 19.8% · Safe to merge
    19.8%