Conversation
socket ids when removing a socket from rooms. Conflicts: index.js
Conflicts: index.js
|
👍 |
|
What kind of perf improvement did this yield? Would be nice to have a benchmark script that can prove this is better. |
|
I thought this would be obviously faster, but it's not :( http://jsperf.com/for-in-or-keys-length (benchmark on browsers, just for reference) |
|
On Chrome, isEmpty is faster than !Object.keys(data).length (it is not the case with Firefox). I suggest to have a look at: var nIter = 1000; function isEmpty(data) { console.time("isEmpty"); console.time("!Object.keys(data).length"); |
|
@manubb sorry, my setup for benchmark was wrong. |
|
On http://jsperf.com/for-in-or-keys-length/3 on Chrome, isEmpty is almost 4 times faster. |
|
The performance on firefox was bugging me... the test is wrong ! You're using integers as keys, |
|
And a fixed test for nodejs i get on nodejs 0.10 (v8 3.14) isEmpty: 5609ms which is an improvement, but not that radical compared to the previous figures. |
|
Keeping track of a "size" property is the only proper way to avoid that O(n) lookup. |
|
I have posted a new pull request #30 so that deciding emptyness for a room is in O(1). Hence i close this pull request. |
Avoid creation of possibly large object to check if an object is actually empty.