CPU Performance: Objects vs Arrays

normal JS objects = lots of indirection
when you write:
const pos = { x: 10, y: 20 };
you don’t get one neat chunk of memory with [10,20] side-by-side.
instead:
posis a pointer to an object record.inside that record are pointers to each property’s value (
x,y).each value may live somewhere else in memory.
there’s metadata for the object’s “shape” (hidden class).
so to access pos.x, the CPU:
follows a pointer to the object
checks its hidden class to know where
xlivesfollows another pointer to the number value
finally reads the number
that’s a lot of chasing around in memory.
typed arrays = raw, flat memory
when you do:
const pos = new Float32Array([10, 20]);
you literally get:
[ 10.0 | 20.0 ]
just two 32-bit floats back-to-back in one contiguous block of memory.
the CPU can grab both in one go; no metadata, no shape checks, no GC overhead. this layout is exactly what native languages use, and what SIMD loves.






