events: optimize once() and removeListener()#64373
Open
mcollina wants to merge 1 commit into
Open
Conversation
Use a closure instead of a bound state object for the once() wrapper, keep the events object shape in removeListener() by storing undefined instead of deleting keys or reallocating the object, and outline the cold unhandled 'error' path from emit() and the max-listeners warning from _addListener() so both fit within V8 inlining budgets. ee-once +25%, ee-add-remove +12-22%, ee-listen-unique +7-15%, streams/pipe +13.9%. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64373 +/- ##
==========================================
- Coverage 90.25% 90.24% -0.01%
==========================================
Files 741 741
Lines 240990 241196 +206
Branches 45402 45431 +29
==========================================
+ Hits 217502 217666 +164
- Misses 15066 15086 +20
- Partials 8422 8444 +22
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimize the EventEmitter hot paths:
once()wrapper as a closure instead ofbind()+ a state object_eventsobject shape inremoveListener(): storeundefinedinstead ofdelete-ing keys or reallocating the object (eventNames()now filters, matchingStream.prototype.eventNames); removes the now-unusedkShapeModeerrorpath fromemit()(439 → 278 bytecodes) and the max-listeners warning from_addListener()(405 → 288) so both fit within the V8 inlining budgetsbenchmark/compare.js --runs 30before/after all changes:events
streams