-
Notifications
You must be signed in to change notification settings - Fork 7.3k
EventEmitter (yeah...) Prototypal Events Issue #7103
Comments
This has been discussed before: #4366 |
Edit: my bad, didn't fully read #4366. |
I find it odd that the performance of creating event emitters is so critical--wouldn't the performance of adding listeners and emitting events be more important? |
Per each http request, you at least create two event emitters: one for response and one for request. Most probably you'll have more for piping from request and to response. You can try making the change and seeing how it will perform in the node benchmarks, you get a different result. v8 have changed a lot from a year ago. |
Hmm I was under the false impression a null prototype made more of a difference than that. However, even if you're creating ten emitters for each request, Amdahl's law implicates that because the creation of the object for the emitter is such a small percentage of the overall performance, it shouldn't really matter. If you're running through a thousand requests in a second, the time taken to create your two emitters is still less than a millisecond. I guess the theory is all a moot point if in practice it decreases performance. |
Amdahl's law is as applicable here as General Relativity is in a black But anyways. So much is constantly going on in core code that no one call |
Touché :)
Yeah, that's a good point. Assuming two-ish event emitters isn't really foolproof logic. |
This is a "simple" issue, but the need for the event emitter to remain frozen may simply mean it's a tolerable issue.
In summary, because the event emitter does not handle prototypal methods on the
_events
object, there could be conflict, and it certainly makes theemit
's return method return true where it otherwise shouldn't.Best-case change given that the API is frozen: set the
_events
object toObject.create(null)
. This would, incidentally, slightly reduce the time taken to emit an event because there would be no prototype chain.Luckily, because
_events
is a private property, this shouldn't be a breaking change. Even if someone were tampering with the_events
object, they should have the knowledge to not depend on its methods.Thoughts?
The text was updated successfully, but these errors were encountered: