Because of certain limitations, I picked a hybrid approach where I use Entities to simulate AI logic and movement and each entity has a counterpart MonoBehaviour in the scene that does other stuff.
The only thing the MonoBehaviour needs from the Entity is the transform position, nothing else. This is what I'm also syncing in FixedUpdate.
Every fixed step, I perform the following call from every MonoBehaviour instance:
var pos = EntitySpawnerSystem.Instance.GetPosition(_entity);
transform.position = new Vector3(pos.x, pos.y, 0);
EntitySpawnerSystem is a SystemBase class - the GetPosition(Entity e) makes the following call:
SystemAPI.GetComponent<LocalToWorld>(e).Position;
But after reaching around 900 entities, I noticed this becoming a bottleneck. This call alone is taking 40% of CPU time. The call stack looks something like this:
GetPosition() 40.7%
ComponentLookup`1.get_Item() 16.6%
EntityManager.CompleteDependencyBeforeRO() 9.1%
ComponentLookup`1.Update() 7.1%
String.memcpy() 2.5%
...
Is there a better, faster way of getting read-only position data of an entity from MonoBehaviour?