Caching of GetComponentGroup queries

I might just have misunderstood the talks on this topic, but I was wondering, how the engine packs the arrays that are then used by the systems when using the job system.

Let’s say you have your struct of component data called RotatorData like in one of the demos and want to call

var group = EntityManager.GetComponentGroup(typeof(RotatorData), typeof(SometOtherComponent));

When the arrays that this group will contain are packed by the engine to enable linear access patterns when iterated over by the developer will this packing of data happen on every call to GetComponentGroup() or are the latest queries cached to enable faster queries if you call the same query every frame for example?

As mentioned I might just have misunderstood the concept, and would love to know more about how this system really works.

Every ComponentSystem stores a cache of the ComponentGroups created via ComponentSystem.GetComponentGroup. You can access them via ComponentSystem.ComponentGroups if you are interested.

A new ComponentGroup is created for a given set of ComponentTypes for a specific ComponentSystem, upon the first request, and then it is cached. Subsequent calls to ComponentSystem.GetComponentGroup return the cache. We suggest caching the result of ComponentSystem.GetComponentGroup in OnCreateManager anyway, to make sure to avoid any overhead.

Creating a new ComponentGroup allocates GC memory, and it is quite expensive. Using injection or IJobProcessComponentData is the suggested way to access ComponentGroups, so the ECS system takes care of all the work for you unless you need something special like setting filters manually.

Regarding data layout, we don’t repack all the data every time you call GetComponentGroup. You can get here a bit more information regarding how the system works: https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Documentation/content/ecs_in_detail.md#chunk-implementation-detail