4 ms·
It's actually not exactly 50K, and likely varies across Chrome/V8 versions, operating system and/or machine architecture. On my browser the threshold is around
by matharmin 2y ago
It's actually not exactly 50K, and likely varies across Chrome/V8 versions, operating system and/or machine architecture. On my browser the threshold is around 22500 elements. For a quick test, see [1].
The difference in V8 appears to be based on whether or not the array is stored in "large object space" [2], which seems to be used when the object is somewhere between 64kb and 128kb [3] (once again can depend on lots of factors). I wonder how many other optimizations depend on that?
[1]: http://www.lonniebest.com/BadShiftPerformance/ http://www.lonniebest.com/BadShiftPerformance/
[2]: https://issues.chromium.org/issues/42202676 https://issues.chromium.org/issues/42202676
[3]: https://github.com/danbev/learning-v8/blob/master/notes/heap.md#pagesize-in-v8 https://github.com/danbev/learning-v8/blob/master/notes/heap...
- rat9988 2y agoIt has been a long time since I have read v8 source code, but I remember it depended on if the array is holey or not, so it would switch back to object based array instead of a contiguous array. (there were other conditions but it's the notable one I remember)
- mettamage 2y agoReading ff source code, I saw something similar with a hole variable. I haven’t spent enough time on what happens though. A good way to search the ff source code is to look at uniquely named JS functions and take it from there. I searched on reduceRight and found shift because of it.