The title except more, like more more, like lets say 100 000 entities all with one set of variables vs. 1 000 entities with dynamic buffers of many times the set of variables. Both approaches contains the same total amount of total data, but which is preferable. Thanks for anything really. (BTW my guess is the many entities w one set of variables, but I dont know, so I am asking)
Obviously this is variable dependent on size of buffers and num buffers per chunk.
If you think about storage in a chunk, then a stream of componentA in the entity version is no different to a buffer of componentA except for few bytes overhead for buffer.
You’d think the entity version would be faster simply cos you don’t have the slight initial overhead of accessing buffer.
However if you take the most optimal scenario for buffer version of a single entity per chunk with a buffer equal to the size of the chunk, then the buffer version could possibly be faster cos you can store more (possibly 2x) than with the entity version. E.g. Take a chunk size of 36 bytes for simplicity where component A is 4 bytes.
// Entity version
EEE = 24 bytes
AAA = 12 bytes
// Buffer version
E = 8 bytes
AAAAAAA = 28 bytes
Of course you’d also have to consider the jobified state. More dense chunks might mean less threading.
So yeah, variable.
It’d actually be an interesting experiment as it’s not as obvious as it first seems but in such buffer scenario, why bother with entities at all. Just use a big array and parallel over it.
So there is pretty much zero difference, if I understand you correctly? How about if you do complex logic with the data in lets say .ScheduleParallel() job?
You need test and profile you specific use case.
For different scenario, each approach may behave differently.
Stress test and profile results.
Btw., entity don’t have to store data in chunk, if bufer size is not allocated by default, or data size is larger than chunk size. You can resize buffer as required, during entity instantiation for example. Buffer data then will be placed on the heap in memory, saving chunk space.
My first reply was comparing buffer within a chunk but all you’re really asking is whether a single array (buffer) is better than n arrays (components in chunks).
In a single threaded scenario, yes cos no cache misses.
In a multithreaded scenario, the buffer also gets partitioned into n arrays so at this point yes, there’s very little difference beyond what is the optimal batch size for a given thread count.
You can’t change batch size of entities chunk so buffer is better option here too.
It’s a bit mute imo because you either need entities or you don’t. If you don’t, use buffers.
Ok thanks for explaining it for me, i´ll test and see what I get.