https://youtu.be/UJPdhx5zTaw?t=17m43s

Not sure if that advice still stands as it's a few years old, but my
experience has been, in the general case, it is unfortunately faster
to allocate an empty array and use push() than to preallocate an array
of the desired size and populate it.  I have notes above a utility
function I wrote that said I measured a 2x improvement in using push
over Array(size), but I can't tell you now for what sort of size
values that was.

As always, just try it and measure.  I've also found using some of the
native methods helps in the process to understand why the performance
difference is there.

You can probably use something like the native %HasFastProperties() to
check (this means running with --allow_natives_syntax).

There is also %_HasFastPackedElements() in Hydrogen, but I didn't look
to see what the difference is.

On Sat, Feb 20, 2016 at 1:05 PM, Michael Zhou
<[email protected]> wrote:
> If I have
>
> var arr = new Array(50); // Should be dense, I guess?
> arr[20] = 0;
> arr[40] = 1;
> arr[20] = undefined;
> var keys = Object.keys(arr);
>
> Will this access pattern make v8 think arr is a sparse array and change to
> using a hash table?
>
> Also, is copying from old back store to new back store unavoidable when I
> grow the array by doing
> for (var i = 50; i < 100; i++) {
>   arr[i] = 0;
> }
>
> ? Thanks.
>
> --
> --
> 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/d/optout.

-- 
-- 
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/d/optout.

Reply via email to