fix: preserve custom tap options dropped by _tap fast path#227
fix: preserve custom tap options dropped by _tap fast path#227alexander-akait merged 2 commits intomainfrom
Conversation
The fast path added in 9e9ae4d (fix(perf): improve (#224)) only checks for a fixed set of properties (before/stage/context/type/fn) before rebuilding the options descriptor as `{ type, fn, name }`. Any custom user-provided property - notably webpack's `additionalAssets`, used by the processAssets hook - was silently dropped, breaking the webpack `ConfigTestCases > process-assets > additional-assets` test. Tighten the fast-path guard to a strict "only name" check via Object.keys length, preserving the hidden-class optimization for the common `hook.tap({ name: "X" }, fn)` case while restoring correctness for every other call shape.
The previous fix used `Object.keys(options).length === 1` to check
whether the tap options object carries any properties beyond `name`
before taking the fast-path literal construction. `Object.keys`
allocates an intermediate array on every call, costing ~10% on the
common `hook.tap({ name: "X" }, fn)` shape vs the (broken) baseline.
Swapping to a `for...in` scan with an early-break avoids that
allocation and pulls the regression down to within measurement noise
(~3%), while keeping the correctness property - any extra user-
supplied key (e.g. webpack's `additionalAssets`) forces the safe
`Object.assign` slow path.
Benchmarked locally with tinybench, 10 taps per iteration, mean of
three runs:
shape broken for-in delta
string 2.66M 2.50M -6%
{name} 2.16M 2.10M -3%
{name,stage} 1.01M 0.98M -3%
{name,additionalAssets} 2.19M 1.15M -48% *
{name,before} 511K 491K -4%
* inherent: this shape must now take the correct slow path since
the previous "fast" speed was produced by dropping the property.
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
==========================================
+ Coverage 99.09% 99.35% +0.25%
==========================================
Files 15 15
Lines 775 775
Branches 132 128 -4
==========================================
+ Hits 768 770 +2
+ Misses 7 5 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The fast path added in 9e9ae4d (fix(perf): improve (#224)) only checks
for a fixed set of properties (before/stage/context/type/fn) before
rebuilding the options descriptor as
{ type, fn, name }. Any customuser-provided property - notably webpack's
additionalAssets, used bythe processAssets hook - was silently dropped, breaking the webpack
ConfigTestCases > process-assets > additional-assetstest.Tighten the fast-path guard to a strict "only name" check via
Object.keys length, preserving the hidden-class optimization for the
common
hook.tap({ name: "X" }, fn)case while restoring correctnessfor every other call shape.