-
Notifications
You must be signed in to change notification settings - Fork 7.3k
hasOwnProperty
performance issue
#9130
Comments
in my real test i generated string keys to avoiding using integer conversion and i sometimes had 25x slower results var cacheobj = {};
var keys = [];
for(var i = 0; i <= 1000000; i++) {
keys.push(i + ' a long string key a long string key ');
}
console.time('set');
for(var i = 0; i <= 1000000; i++) {
var key = keys[i];
cacheobj[key] = i;
}
console.timeEnd('set');
console.time('get');
var val=0;
for(var i = 0; i <= 1000000; i++) {
var key = keys[i];
if(cacheobj.hasOwnProperty(key)) {
val = cacheobj[key];
}
}
console.timeEnd('get'); results : set: 1355ms set: 1472ms set: 1445ms set: 1351ms |
Surprisingly, results: set: 2153ms
get: 674ms
set: 2165ms
get: 703ms
set: 2243ms
get: 975ms
set: 2257ms
get: 641ms
set: 2539ms
get: 659ms Though , In browser environments |
If the function createMap()
{
function map(){}
map.prototype = Object.create(null);
return new map();
} using the |
Thank you very much, |
I dont have idea why the performance like this in node.Hope someone with better knowledge on node innerworkings will clarify . |
Can't claim to be an expert on the matter, but I have tried this in v0.11.14 (V8 version 3.26.33 vs 3.14.x in v0.10.x) and it seems that the problem is gone. Unfortunately, I don't think there's much that can be done about, unless you plan on changing some of the V8 inner workings. |
Yes. This is a V8 issue and not much we can do in Node. |
When i call
hasOwnProperty
some times has good performance and some times 20x slower. for example when i run it 5 times, then 2 times become very slow but 3 times is fast!!! but when i don't usehasOwnProperty
then my code always has good performance!codes :
The text was updated successfully, but these errors were encountered: