events: optimize various functions
authorBrian White <mscdex@mscdex.net>
Thu, 5 Feb 2015 20:35:33 +0000 (15:35 -0500)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 9 Feb 2015 16:47:49 +0000 (17:47 +0100)
commitb677b844fc1de328a0f2b0151bdfc045cb5d0c81
tree395cbae33a97b380077ead592ca95aad6d6076e0
parentc86e383c41f35b17ba79cc1c6dbfff674214177d
events: optimize various functions

Cache events and listeners objects where possible and loop over
Object.keys() instead of using for..in. These changes alone give
~60-65% improvement in the ee-add-remove benchmark.

The changes to EventEmitter.listenerCount() gives ~14%
improvement and changes to emitter.listeners() gives
significant improvements for <50 listeners
(~195% improvement for 10 listeners).

The changes to emitter.emit() gives 3x speedup for the fast
cases with multiple handlers and a minor speedup for the slow
case with multiple handlers.

The swapping out of the util.is* type checking functions with inline
checks gives another ~5-10% improvement.

PR-URL: https://github.com/iojs/io.js/pull/601
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
lib/events.js
test/message/stdin_messages.out