perf: cool off EventEmitters

This commit is contained in:
cha0s 2019-04-17 00:05:12 -05:00
parent 0952ffbd0e
commit d919af7812
2 changed files with 5 additions and 7 deletions

View File

@ -12,7 +12,7 @@
- ✔ Eliminate immutable.toJS()
- ✔ Track dirty entity state (entityList.tick())
- ✔ Investigate visibleEntities path
- Investigate lookupEmitListeners path
- Investigate lookupEmitListeners path
- ❌ Investigate visibleBoundingBoxes path
- EventEmitter::emit is too hot
- EventEmitter::emit is too hot
- ❌ entityList.fromJSON()

View File

@ -25,7 +25,8 @@ export function EventEmitterMixin(Superclass) {
return;
}
for (const {once, type, namespace, fn, bound, that} of listeners) {
for (let i = 0; i < listeners.length; ++i) {
const {once, type, namespace, fn, bound, that} = listeners[i];
const offset = type !== '*' ? 1 : 0;
if (once) {
@ -86,10 +87,7 @@ export function EventEmitterMixin(Superclass) {
lookupEmitListeners(type) {
return ['*', type].reduce((r, type) => {
if (type in this.$$events) {
r.push(...this.$$events[type]);
}
return r;
return r.concat(type in this.$$events ? this.$$events[type] : []);
}, []);
}