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
This is the article that says so: https://v8.dev/blog/elements-kinds …. "Operations on packed arrays can be optimized more aggressively." "Operations on holey arrays require additional checks and expensive lookups on the prototype chain." No longer true?
1 reply 0 retweets 1 like
Mathias Bynens Retweeted Mathias Bynens
Still true. The nuance ishttps://twitter.com/mathias/status/1066410153057038336 …
Mathias Bynens added,
-
-
Right, there's an additional hole check for holey arrays, sure. But since otherwise we've worked hard to eliminate all the really serious performance cliffs with holey arrays, I'm still wondering if users need to worry about the holeyness of 'new Array(N)' in reality.
1 reply 0 retweets 4 likes -
Whenever I read holey arrays, the “oh holy night” Christmas choral melody begins to play in the back of my head... I also typical imagine the whole v8 team singing “oh holey array” to the same tune, dressed as Santa and co...
1 reply 0 retweets 3 likes - 3 more replies
New conversation -
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.