2 ms·
Perhaps I should because it seems like you simply listed ways to sort. My understanding is any ECS implementation would always spend the time bookkeeping to pr
by jayd16 5y ago
Perhaps I should because it seems like you simply listed ways to sort.
My understanding is any ECS implementation would always spend the time bookkeeping to prevent O(n^4) or other combinatoric explosion. Systems run every frame while entities are spawned much less often, if at all between load screens.
Nested linear searches as you suggest would also blow out any locality improvements, which made the suggestion even more confusing to me.
Unity's implementation is deeply focused on keeping component data tightly packed so systems can quickly loop over them with SIMD, or even batch them across other threads. They keep entities sorted in buckets by component list, eg entities with components A, B, and AB are grouped separately (but still as arrays of the underlying component data).
They can trivially pass organized sets of arrays to any system that may need them. No linear searching is required as the arrays of separate component data are naturally matched. If a system needs to operate on A and B, the paired arrays are ready made.
...but what do they know?