Repository navigation
events: prefix events to prevent breaking on known object properties #728
Description
Activity
- addedeventsIssues and PRs related to EventEmitter and the events module.Issues and PRs related to EventEmitter and the events module.
on Feb 5, 2015 We just solved a similar problem with console timer labels. We ended up going with a
Map, butObject.create(null)worked equally as well.Sounds like a spot to use
Map. (Assuming it has decent perf)I don't think that the performance of Map and Weakmap are better than
Object.create(null)According to this micro-benchmark (yep) you could expect map to be twice as slow:
http://jsperf.com/map-vs-object-as-hashes/14
Hash access may well not be the/a performance bottleneck in events though.
@meandmycode You are comparing linear array to hash map.. you need to either use string keys or very sparse numeric indices to force the object into a dictionary mode.
Secondly the comparison is not fair unless you also factor in the cost of checking if a key is
"__proto__".So when using an object as a true string hash map (arbitrary string is supported, including proto) vs using Map, the speed is not surprisingly very much equal http://jsperf.com/map-vs-object-as-hashes/24
One thing to note is that the current version of v8 hasn't required explicit checking for
__proto__.Also, @bnoordhuis just pointed out on another issue that
Object.create(null)is 15-30x slower than an object literal. I don't think it's worth it in this case.- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on May 24, 2015 - added a commit that references this issue
on Mar 10, 2016 I opened pull request to add a test for this to
known_issues: #56492 remaining items
- added a commit that references this issue
on Mar 14, 2016 - added a commit that references this issue
on Mar 16, 2016 - added 2 commits that reference this issue
on Mar 30, 2016 - added a commit that references this issue
on Apr 19, 2016 - added a commit that references this issue
on Apr 25, 2016 - added a commit that references this issue
on Apr 26, 2016
In the EventEmitter the events are stored in an plain
Objectinstance. The event names that you use are added directly as property on the object so when you event names such as__proto__it will break. One solution is to prefix the keys with a char such as~.Example case:
Willing to create pull request if bug requires fixing ;)