Skip to content

Commit

Permalink
Scavenge uncompacted slots already when finding next free index
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Oct 22, 2013
1 parent 541392b commit a1b2fe7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -7,3 +7,11 @@ Benchmarks:

- [Single listener](http://jsperf.com/1234567213/7)
- [Multiple separate listeners](http://jsperf.com/1234567213/8)

##Pitfalls

Fast emitter is relying heavily on the fact that strings are internalized in V8. You shouldn't worry about this because in normal use event types are not dynamically generated but originate from string literals.

However you should be aware that if you do something like dynamically concatenating strings to create event name, you will slow things down.

If you have huge amount of different event types on the same event emitter, then performance will suffer. Again, in practice there are not a huge amount of different event types on the same emitter active at the same time though.
7 changes: 5 additions & 2 deletions fastemitter.js
Expand Up @@ -417,13 +417,16 @@ function EventEmitter$_nextFreeIndex( eventName ) {
}
}
this._resizeForHandlers();
//Todo no-recursion
return this._nextFreeIndex( eventName );
}
else if( this[i] === void 0 ) {
this[i] = eventName;
this._eventCount++;
return i+1;
return i + 1;
}
else if( this[ i + 1 ] === void 0) {
this[i] = eventName;
return i + 1;
}
}
this._resizeForEvents();
Expand Down

0 comments on commit a1b2fe7

Please sign in to comment.