Fascinating, thank you for the response! 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.
What data structures does V8 use under the hood to store arrays? Is 100k the only critical threshold? A link to the source would suffice if it's at all readable :) 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). By "grown" do you mean "a new larger array is instantiated which inherits members from the old array"? Cheers On Sunday, December 15, 2013 3:49:31 AM UTC-8, Jakob Kummerow wrote: > > 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]<javascript:> > > 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] <javascript:> >> 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] <javascript:>. >> 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.
