perf: assign variadic and array chainable methods directly
G4
11d ago+22+22+01234567890123456789-23-23-01234567890123456789
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 andjestpass.- 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.