Why is the new Array slow?

when comparing operations

var fat_cats = cats.slice()

to

var fat_cats = new Array(cats.length)

performance differences are confusing.

In firefox and chrome it new Arrayworks slower (when it should be faster, it just allocates an empty array and does not iterate over it)

Where as in IE8 is new Arrayfaster (which is just confusing)

Any explanation appreciated.

+3
source share
1 answer

I found this out by looking at the source code for the functions of the V8 array.

If the array contains more than 1000 elements and is called .slice, a function with the name is used SmartSlice, the element used in the SimpleSlicefunction.

SimpleSlice ( , ). SmartSlice, , .

, 10 000 1000, ( ), 1000 , SmartSlice ~ 36% , .


V8 , , Firefox , , - (, ).

, Firefox js/src/jsarray.cpp!array_slice, Firefox : .slice DenseCopiedArray DenseAllocatedArray, , -, V8.

+8

All Articles