AFAICT, there is no good way of pre-allocating a large array in JavaScript. new Array(LEN) creates an array that’s slower due to it being “holey”. Time for Array.create()?
-
-
Replying to @rauschma
What if you fill the array after the create? Array(10).fill(0)
1 reply 0 retweets 1 like -
Right, that would be my thought too. Ideally a pattern we could make fast (assuming it's slow and causes perf issues... I've not tested)
2 replies 0 retweets 2 likes -
Replying to @aerotwist @bxlewi1
IINM, that doesn’t help: once an array is holey, you can’t go back (at least on V8).
3 replies 0 retweets 3 likes -
1 reply 0 retweets 1 like
-
Replying to @aerotwist @rauschma and
There’s an open
@v8js issue to consider marking the .fill()ed array packed in the common case: https://bugs.chromium.org/p/v8/issues/detail?id=6892 …1 reply 0 retweets 4 likes -
Replying to @mathias @aerotwist and
If that turns out to be feasible, the “a sufficiently advanced compiler” argument applies, and we don’t need Array.create or any other new language features.
1 reply 0 retweets 7 likes -
Replying to @mathias @aerotwist and
It would be very interesting to see how this turns out.
1 reply 0 retweets 0 likes -
Replying to @sendilkumarn @mathias and
I'm wondering what's the concrete example where "holey arrays" are significantly slower than "packed arrays"?
3 replies 0 retweets 1 like -
Replying to @bmeurer @sendilkumarn and
I just assumed they were (from what I’ve read over the years)! If not then that’s even better!
1 reply 0 retweets 0 likes
Operations on holey arrays can still be optimized — just not as aggressively as for packed arrays.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.