Comments (3)
This comment was a tongue-in-cheek reply to @Raynos. We have worked together with @jcorbin at Uber on projects including TChannel and Hyperbahn. Jake and Josh observed from iterating on performance improvements informed by production flame graphs that the EventEmitter was unnecessarily wasteful, and created an alternative.
The alternative allows us to bypass a dictionary lookup from event name to emitter state, by placing the emitter state and interface on a property of the event emitter itself.
function Beeper() {
this.beepEvent = this.defineEvent("beep");
}
util.inherits(Beeper, EventEmitter);
var beeper = new Beeper();
beeper.beepEvent.on(onBeep, recorder);
beeper.beepEvent.emit({volume: 1});
function onBeep(beep, recorder) {
}
Consequently, looking up an event benefits from v8 hidden classes. We also observed that we do not need an array in the common case of a single observer, reducing garbage collection. The new event emitter also sends an observer-selected context object, which helps us re-use functions for multiple consumers and avoid closures in many cases.
You will note that Node.js does not use event emitters internally. This optimization is just one of many steps in the walk away from abstractions to high performance. The next logical step is to completely eliminate the notion of extensible subscription and just have delegates or hooks for all of the anticipated consumers of an event and dispatch on them with individual, manually ordered method calls, much like DOM level 1 events like "onclick".
In short, there are trade-offs. I think that we all go home happy if we take an opt-in layered approach that includes both higher and lower layers than what Node.js currently exposes. The higher level abstractions trade performance for robust composition, and the lower would trade ergonomics for speed.
from ama.
I have similar opinions that event emitter is not needed.
The only thing I like about it is an error handling contract. "Ive just allocated this thing that may error in the future please deal with it lol"
from ama.
Thanks for the thorough reply!
from ama.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ama.