> Eliminating per-element object overhead — This is the biggest win (~5-6x)
I feel like this phrasing might be easy to misinterpret. Without carefully considering the context, it seems like it's implying that objects have higher overhead than arrays, and my intuition is that this is true, but I'd argue that there's a potentially more relevant way of looking at things.
In the "object of arrays" layout, you have one object and three arrays, but in the "array of objects" layout, you have one array and N objects, where N is the size of the array. Even if the overhead of objects was the same as can array, you'd be looking at more overhead as soon as you went past three elements. In fact, even if the overhead of an object was lower than the overhead of an array, you'd still reach more overhead with the "array of objects" layout if you have enough elements to make up for the difference. With a TypedArray (or an array of a single type that's optimized by the runtime in the way described fairly early on in the article), you're not looking at an extra level of indirection per element like you would with an object.
I'd be curious to see what the results would be if they repeated the "array of objects" benchmark with an "array of arrays", where each element is an array of size 3. I could imagine them being quite similar, but I'm also not sure if there's even more nuance that I'm falling to account for (e.g. maybe the runtime would recognize that an array of N/3 elements each being an array of 3 numbers could be "flattened" to an underlying representation of array of size N in memory and perform the same optimizations.
I think the meta lesson here may be that intuition about performance of arrays in JavaScript might be pretty tricky. At least in terms of external semantics, they're supposed to be roughly equivalent to objects with numbers as keys, but in practice there are probably enough optimizations being done (like the implicit recognition of an array of numbers as described in the article) that I suspect that intuition might be a bit naive in a lot of cases, and it's probably better to verify what's actually happening at runtime rather than trying to guess. (The meta meta lesson is that this is true for a lot of things in pretty much every language, and it's sometimes going to be necessary to verify your assumptions about what performance will be, but I think that's something easy to fail to do even when you're aware of it being an easy trap, so having some general things to look out for like arrays potentially not being intuitive can still be helpful).
> I'd be curious to see what the results would be if they repeated the "array of objects" benchmark with an "array of arrays"
Arrays are objects, so I’d be surprised if it made much difference.
Much of a difference from which, the array of objects or an object containing arrays? The article points out at least one major optimization that the runtime performs on arrays that doesn't (and as I understand it, can't) exist for objects. My point is that it's not obvious whether there are others, and if so, where they might apply.
Pretty much the entire last paragraph of my comment that you responded to is an argument that it's potentially wrong to just naively assume "arrays are just objects". It's not clear to me why you're confident that this is wrong without giving any additional context that clarifies whether you've actually considered that point of view or not.
> Sometimes even SIMD (eez nuts?)
I'm a bit rusty here, does V8 actually do auto-vectorization of JavaScript code these days?
I don't think v8 does any auto-vectorization unless it's been added since 2024 which was the last time I checked.
Thanks! That tracks; ~a year ago I tried fruitlessly to get some numerical stuff to vectorize in Node.js... gave up and switched to WASM SIMD.
> This test is a manufactured problem, a silly premise, false test cases and honestly dishonest if not ignorant
It’s amazing how vitriolicly wrong people can be. Before publicly criticizing someone in the above way, prove them wrong first. Don’t just assume they’re wrong.
But only llms hallucinate!