So I'm writing a custom scripting language specifically for ECS like applications, and as the whole point of ECS is to minimize cache misses I figured I might as well apply that to the scripting language as well. Currently my interpreter uses a virtual stack (std::vector<std::byte>
) to store all of it's variables. I was wondering if the fact that the memory that my interpreter uses contiguous memory makes it more cpu cache friendly. Since the memory is being semi randomly accessed (Though mostly close together) I'm guessing the benefits wouldn't be as good as if I were reading them in a sequential and predictable fashion. What are your thoughts wise people of Stack Overflow?
Contiguous memory is nice, because many parts of the memory subsystem benefit from locality of reference. But the scale at which the various parts work varies. Typically CPU cache lines are smaller than the page size, e.g. 64 bytes vs 4096 bytes. Your vector will likely span multiple cache lines, so contiguity at that scale does not really matter, but it would benefit from contiguity at the page size.