New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the library #257
Comments
Yeah, I don't think I was around when that was introduced. I think emitAsync was a PR which I didn't look too deeply into. I'm down for a major bump. 😁 |
Yeap. This lib has a bit more issues that just emitAsync and currently i have not an idea how to fix that and keep 100% compability. |
@RangerMauve I just found out that wildcard emitter benchmark is totally fake 😄 EventEmitter2/test/perf/benchmark.js Line 11 in f3f642f
EventEmitter2/test/perf/benchmark.js Lines 38 to 44 in 799d2f8
Previously i wonder how that heavy code has a performance only three times less than highly optimized plain emitter. Even plain namespace.split('.') has performance only around 3M op/sec)) So, the secret is revealed. That benchmark tests an emitter not in wildcard mode and the real performance is near 300k operations/sec, not 3.5 millions :D It's 40-50 times slower than simply emitter has.
|
Ah dang! I wonder how long it's been that way. 😂 |
@RangerMauve not for long, It looks like just about 9 years :) |
When I was using this library actively at work (years ago) I exclusively used it for the wildcards. 😂 |
@RangerMauve Hm. I never needed to use wildcards emitters, at least something harder than basic one level wildcard e.g.
Even in a case of emitting a simple wildcard event (test.*) it's 75 times slower than a general emitter. |
The library has strange, almost dead conditional branches with checking
_events
and_all
props, since _events is always truly, moreover it is initialized with object even in wildcard mode, but never used.EventEmitter2/lib/eventemitter2.js
Line 222 in 9f8a837
The _all array stay initialized for always after being first time used.
So in fact these branches are dead (never executed at all):
EventEmitter2/lib/eventemitter2.js
Line 459 in 9f8a837
EventEmitter2/lib/eventemitter2.js
Line 567 in 9f8a837
These checks are useless:
EventEmitter2/lib/eventemitter2.js
Line 712 in 9f8a837
EventEmitter2/lib/eventemitter2.js
Line 463 in 9f8a837
EventEmitter2/lib/eventemitter2.js
Line 876 in 9f8a837
EventEmitter2/lib/eventemitter2.js
Line 904 in 9f8a837
And so on.
It seems we should set _events and _all to null if there are no any listeners, or use internal flag to determine if there are any listeners to avoid object reinitiazlization.
emitter.emitAsync
has bad logic and returns very strange values.If _all and _events was not initialized yet it returns false (but fortunately is never executed) not even Promise.resolve(false).
For
newListener
event and if the vent has no listeners it returns [false]If _all and _events is initialized and there are no any listeners - []
Moreover it's resolves promises from
all
listeners array and array of specific event type so there is no ability to determine is value returned fromall
listener or from a listener of specific event type.I bellive this should be refactored in major version:
all
listeners, just wait while they will be resolved.The text was updated successfully, but these errors were encountered: