Conversation
Codecov Report
@@ Coverage Diff @@
## master #85 +/- ##
==========================================
- Coverage 75.23% 73.45% -1.78%
==========================================
Files 34 35 +1
Lines 432 437 +5
Branches 84 82 -2
==========================================
- Hits 325 321 -4
- Misses 89 98 +9
Partials 18 18
Continue to review full report at Codecov.
|
| */ | ||
| return function runHooks( hookName, ...args ) { | ||
|
|
||
| if ( ! validateHookName( hookName ) ) { |
There was a problem hiding this comment.
This removes all validation from hooks names when applying them.
There was a problem hiding this comment.
This removes all validation from hooks names when applying them.
What's the worst case scenario here?
The assumption I'd made, noted in extended commit description of a0e6eb6, is that validation of the hooks takes place when they're added, and if no hooks exist which match the hook name (a given if it's an invalid hook name), nothing would occur.
| function createHooks() { | ||
| const actions = {}; | ||
| const filters = {}; | ||
| const actions = Object.create( null ); |
There was a problem hiding this comment.
Not clear why this is changing this here, is this performance related or required for other changes here?
There was a problem hiding this comment.
There was a problem hiding this comment.
Ok, got it - I didn't see that this was required for the other changes to work. Nice!
Unnecessary because a hook cannot be registered with an invalid hook name, so it would not pass the subsequent condition to check that a hookset with corresponding name exists.
Even if we don't intend to return value, no harm in assigning to args[ 0 ]
71bd540 to
8d5854b
Compare
|
Looks good to me! |
Foreseeing
runHooksbecoming a hot code path, I took to making a few small micro-optimizations, improving the handled and unhandled hook performance by approximately 42% and 172% respectively on my machine (handled meaning at least one hook handler exists). Standard benchmarking caveats apply (Node V8 engine, machine-specific, benchmarks themselves limited in real-world applicability).Before:
After:
Optimizations include:
doAction( '__current' )to attempt to find handlers for the internal property, though would fail after the second condition, since array would not have.handlersproperty. To me, it's more concerning that we're allowing for this special key to exist with special treatment in the same scope as other hook handlers.hasOwnProperty, faa0ed3, jsperf)Object.create( null )is to avoid issues with prototype property access:!! ( {} ).valueOf // true!! Object.create( null ).valueOf // falseTry yourself: