Comment #1 on issue 2190 by yang...@chromium.org: Performance on TypedArray
This issue is neither new nor limited to Chrome (as can be seen on jsperf).
The reason is simply that while constructing Array is done exclusively in
constructing a TypedArray involves the browser binding (at least in Chrome)
and allocation outside the VM's heap. The former can be properly optimized,
while the latter cannot. Future optimizations in this area are already on
our radar, but have rather low priority.
The performance difference you see in your read benchmark can simply be
explained by the Array object being uninitialized. Out-of-bound accesses
are inherently slow. I revised your read access benchmark -
The same applies to the write access benchmark: sequential out-of-bound
writes require the array length to be changed every time. Random write
accesses causes the VM to represent the array as a hashtable rather than a
real array in the memory. Those issues do not affect typed arrays since
those are simply allocated as a memory block in the heap.
Generally speaking, typed arrays are good if you want to allocate a
long-living dense array with a certain type and size. Array objects are
better if you want to create temporary arrays often.
However, I would advise against micro-benchmarks like those on jsperf as
with intricate heuristics that often work well for comprehensive
applications, but not for micro-benchmarks that stress one small test case.