Avoid false sharing among worker threads with entity-component-system

227 views Asked by At

A cache efficent way of storing components in ECS is dividing up types of components into large arrays, then having each system iterating over the components. However, let's say I also want to avoid false sharing between the rendering and the physics thread trying to access the coordinates of an entity at the same time.

Let's assume a cache line is 64 bytes large. And let's say I have a 'Positions' array that is 1 GiB. I can divide it into 64 bytes pages, and I only need one boolean value to store wether the page is busy ( being written ) or not. Using std::vector<bool>, that uses only 1 bit for every bool, that would take up 2 Mib of memory.

So far it sounds doable. However, I still don't have a way to efficently deal with the situation where a worker thread finds a page is busy.

Should I busy wait? Is there a common pattern to solve this problem?

Or more importantly, is this painless overengineering? I'm just trying to make my "homework" framework extension proof, for a matter of learning. Never having made a large engine, I don't know if false sharing is actually a noteworthy performance cap in this situation.

0

There are 0 answers