I'm currently writing a simple ECS architecture for an engine and I have the fundamentals in place but after reading up on this architecture, it is designed in such a way that the memory is contiguous for all of the components and systems.
My understanding is that the components should be stored right after each other so they are not somewhat fragmented in memory? So that way when I update all of the components, the cache prefetcher can help out performance by fetching the next lot of components (limited understanding) without jumping around.
class system1 final
{
public:
//...
private:
std::vector<component1> m_components;
};
class system2 final
{
public:
//...
private:
std::vector<component2> m_components;
};
Then in some manager, you would initialize the systems so that they are as close as possible in memory.
But what if I wanted to allocate additional memory in the systems? Like a few extra buffers for dealing with system-specific information. That would then separate the component buffers so they are no longer next to each other.
class system1 final
{
public:
//...
private:
std::vector<component1> m_components;
std::vector<int> m_somebuffer;
std::vector<int> m_someOtherBuffer;
};
class system2 final
{
public:
//...
private:
std::vector<component2> m_components;
};
- Would this cause any problems and does this break the whole ECS principle?
- What should I be considering here for maximum performance without stumbling on issues later?
I don't want to optimize prematurely but knowing what makes an architecture fast and somewhat optimal during development is an interesting topic for me. Any input is greatly appreciated.