Search Unity

Would pooling Entities be faster than moving them in memory?

Discussion in 'Entity Component System' started by Arowx, Jul 9, 2019.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Abstract Scenario: You add a component/tag Z to entity A to ensure it is processed by a system that will generate a new entity B. A is now destroyed.

    I would imagine the system memory activity for this would go a bit like this.

    Move A to AZ.
    Delete old A.
    Read AZ and then Create B.
    Delete AZ.

    With adding and removing entities from one system to another having memory allocations/deallocations.

    Would an entity pooling system reduce the memory workload of the system as it would only need to enable an entity and change the data. Combined with an approach where tagging an entity is frowned upon as you should only move the data you need and not the entire entity + tag then you could massively reduce the memory bandwidth needed?
     
  2. temps12

    temps12

    Joined:
    Nov 28, 2014
    Posts:
    41
    ECS is built for linear access of data and if there was some kind of pooling like you suggest there would be holes in the chunks where disabled entities are. So iterating over them would be slower. You still have to pay the price of copying the data to the new chunk so you wont save anything there. Sure, when you remove the entity from the old chunk the last entity of that chunk will take its place so there wont be a hole and with pooling you would disable it somehow.

    I think they made the right choice in making it the way it is now. Sure, it would be nice if the actual moving of entities could get faster somehow, maybe they could burst it or make it in C++ or something to speed things up.
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    So would it be faster to iterate over 'disabled' entities than re-shuffle the memory every time something is added and removed. I would expect it depends on the amount of dynamic activity a set of systems go through, e.g. bullet/explosion systems in games could be hyperactive in creating and destroying entities over and over when a pooling system could be more performant.

    Is there even the flexibility to use an entity system in a pooling manner?

    In a way is this memory management aspect of DOTS is similar to the garbage collection problem of the OOP systems.

    Has Unity or anyone deep-profiled the DOTS system to assess what the bandwidth impact would be on very active dynamic systems with a pooling approach and the default approach.
     
    Last edited: Jul 9, 2019
  4. They already told us to use a boolean instead. Effectively it's a pooling system. You pay the price to loop over every entity but you will only process whatever is alive currently.

    IDK what's your point with this thread.
     
    Antypodish likes this.