← Back to Pull requests

perf: assign variadic and array chainable methods directly #398

Open
unknown opened this pull request with 234 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 22, 2026 15:14 UTC
Author

variadic and arrayChainable now set their methods directly, not through Object.assign with a new object. P.array(...) is then cheaper to create, so inline patterns are faster. The results do not change.

Built dist/index.js, ms per loop over mixed inputs, 20 rounds, Mann-Whitney test (Node 24, Apple M2 Max):

| Benchmark | Before | After | Change |
|---|---:|---:|---:|
| Tuples with ...P.array(), 7 branches | 2.26 | 1.63 | −28% |
| 3 inline isMatching patterns, one with P.array | 0.47 | 0.34 | −27% |
| Nested objects with [1, ...P.array(P.number)] | 0.61 | 0.46 | −25% |
| Selections with P.array(P.select()) | 2.57 | 2.12 | −18% |
| Event reducer, 14 inline branches | 2.58 | 2.20 | −15% |

Other benchmarks did not change. Gzip size: +16 bytes.

Checks:

  • tsc --noEmit, the build and jest pass.

  • Old and new results matched on 2M random patterns and values.
  • <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Assigns Symbol.iterator, optional, and select directly on the pattern object instead of building a new object with Object.assign. Creating P.array(...) patterns is now cheaper, which speeds up inline patterns by 15–28% with identical behavior.

    <sup>Written for commit 240a021c7b8771373b8dbbfd4b7164382171dc7b. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/gvergnaud/ts-pattern/pull/398?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 234 lines (+175 / -59) across 2 files Reviewer: g4lb Review duration: 11720m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 234 lines diff across 2 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.327
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #398"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.4% · Safe to merge
    22.4%