events: optimize once() and removeListener() · nodejs/node@73e1701 · GitHub
Skip to content

Commit 73e1701

Browse files
mcollinaaduh95
authored andcommitted
events: optimize once() and removeListener()
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> PR-URL: #64373 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 86bca58 commit 73e1701

5 files changed

Lines changed: 82 additions & 78 deletions

lib/events.js

Lines changed: 74 additions & 70 deletions

test/fixtures/errors/events_unhandled_error_common_trace.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node:events:<line>
2-
throw er; // Unhandled 'error' event
3-
^
2+
throw er; // Unhandled 'error' event
3+
^
44

55
Error: foo:bar
66
at bar (<project-root>/test/fixtures/errors/events_unhandled_error_common_trace.js:9:12)

test/fixtures/errors/events_unhandled_error_nexttick.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node:events:<line>
2-
throw er; // Unhandled 'error' event
3-
^
2+
throw er; // Unhandled 'error' event
3+
^
44

55
Error
66
at Object.<anonymous> (<project-root>/test/fixtures/errors/events_unhandled_error_nexttick.js:6:12)

test/fixtures/errors/events_unhandled_error_sameline.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node:events:<line>
2-
throw er; // Unhandled 'error' event
3-
^
2+
throw er; // Unhandled 'error' event
3+
^
44

55
Error
66
at Object.<anonymous> (<project-root>/test/fixtures/errors/events_unhandled_error_sameline.js:6:34)

test/fixtures/errors/events_unhandled_error_subclass.snapshot

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)