Performance: EventEmitter class
MEDIUM IMPACT
This affects how efficiently events are handled and how quickly the application responds to user or system actions.
const EventEmitter = require('events'); const emitter = new EventEmitter(); for(let i = 0; i < 1000; i++) { emitter.on('data', () => { setImmediate(() => { // heavy task deferred asynchronously for(let j = 0; j < 1e6; j++) {} }); }); } emitter.emit('data');
const EventEmitter = require('events'); const emitter = new EventEmitter(); for(let i = 0; i < 1000; i++) { emitter.on('data', () => { // heavy synchronous task for(let j = 0; j < 1e6; j++) {} }); } emitter.emit('data');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous listeners in EventEmitter | N/A | N/A | N/A | [X] Bad |
| Asynchronous deferred listeners in EventEmitter | N/A | N/A | N/A | [OK] Good |