3 ms·
The simple naive way is to indirect through a pointer, so your array elements would each be say 8 bytes pointing to things of various types. In practice you ca
by obl 8y ago
The simple naive way is to indirect through a pointer, so your array elements would each be say 8 bytes pointing to things of various types.
In practice you can play a lot of tricks to avoid the overhead.
One example would be NaN-tagging. Another would be to speculatively store the array elements "unboxed" as long as they all have the same type and fallback to pointers when the array actually becomes heterogeneous.
I'm not up to date on what today's javascript JIT do for storage optimizations but when you add in sparse arrays etc, I'm sure it's quite involved.