perf: assign variadic and array chainable methods directly

G4
11d ago
+22-23

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):

BenchmarkBeforeAfterChange
Tuples with ...P.array(), 7 branches2.261.63−28%
3 inline isMatching patterns, one with P.array0.470.34−27%
Nested objects with [1, ...P.array(P.number)]0.610.46−25%
Selections with P.array(P.select())2.572.12−18%
Event reducer, 14 inline branches2.582.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.

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.