I had some misconceptions about chunks myself and knowing how they work in Unity is important, so I’ll share some things I know.
Each combination of components is stored in its own chunk. When you are trying to get all ComponentData of a specific type usually you get it from entities from a lot of different chunks. If you ask for everything with Health in RTS game you get all the units, buildings, destructible objects all from a bunch of different chunks.
When iterating through chunk, switching between chunks can or will result in a cache miss. But when iterating inside the same chunk you are going linearly through L1 cache and it is very fast. So it is better not to divide entities into many archetypes.
Each SharedComponent’s value creates it’s own chunk as if it is a different component.
Each time you change entity’s archetype by adding or removing components you are actually moving these entity’s memory (from each component array) to another chunk. So it is quite slow compared to other things.
Burst compiler speeds up iteration (and most operations) over entities 100x or more. It is faster to iterate over a 1000 entities to find one with a particular value, than it is to tag it and make it move to another chunk and filter it that way. You can do millions of iterations each frame for a tiny cost and it probably will be on a job on worker threads.
Since iteration is so cheap I personally dont change my entities’ archetypes and if I need it to receive an event I just have the component of that event on potential recipients at all times and change this component’s value to raised whenever it is raised. Besides adding and removing components always happens on the main thread, and this way I can avoid that.
Some benchmarks here: ( Flagging for filtering: Better to add/remove empty component or poll over component data int. - #10 by iam2bam )
Since raycasts are also jobified I now do all my projectiles in pure ecs with potentially thousands of raycasts each frame for a tiny cost.
So fast because it’s linear memory access with rare cache misses.
Because of Burst’s voodoo.
Because of easy multithreading.