There, fixed that for ya: http://jsperf.com/preallocated-vs-dynamic-arrays/3

Pre-allocated vs. dynamically grown is only part of the story. For
preallocated arrays, 100,000 just so happens to be the threshold where V8
decides to give you a slow (a.k.a. "dictionary mode") array.

Also, growing arrays on demand doesn't allocate a new array every time an
element is added. Instead, the backing store is grown in chunks (currently
it's grown by roughly 50% each time it needs to be grown, but that's a
heuristic that might change over time).


On Sun, Dec 15, 2013 at 7:31 AM, Boris Cherny <[email protected]> wrote:

> Befuddled javascript engineer here.
>
> Test case here: http://jsperf.com/preallocated-vs-dynamic-arrays/
>
> I'd expect a pre-allocated array to be faster than instantiating a new
> array every time and copying values over from the old one, if that's what's
> going on under the hood. Or is V8 using some sort of linked list
> internally? Can someone help explain what's going on with these test cases?
>
> =Boris
>
> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to