kgorking / ecs

A header-only/importable c++20 implementation of an entity-component-system (ecs), with focus on a simple interface and speed.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better component storage.

kgorking opened this issue · comments

It's time to ditch std::vector.

Insertions/removals are too slow, and the storage type is shared by all components in the vector, which means component storage can't be optimized based on tiered usage patterns. It also doesn't take full advantage of pmr allocators (no data interleaving).

The 'translation' component is a perfect example of this difference in usage, from static level decorations that never changes, to particle cannons that can spawn hundreds of new entities with translations components on them per second.

The way storage is implemented now, if the particles happen to have lower entity ids than the static level decorations, then all the static translation components would also have to be moved. This of course causes unacceptable and unnecessary moving of data, which shall be fixed.

The current working idea is to use tiered storage, where components that are never removed go into T0 storage, and components that are inserted/removed often go into T2 storage. If they stay in T2 long enough, they are moved to T1, and if they stay there even longer, they are moved to T0.

T0: std::unique_ptr<T[]>
T1: ?
T2: std::vector