Search Unity

Question Doesn't filtering (eg: WithAll) remove the performance benefit?

Discussion in 'Entity Component System' started by Dinamytes, Jan 4, 2021.

  1. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    I have been having a hard time getting into ECS, i can't seem to understand how some behaviours work that will give me an advantage over my custom code, eg:
    • 100000 entities with a Position component
    • 100 random of those entities with Position components with also a Translation component that will change the Position in a system.
    The translation component may have a linear memory layout in this case but if the Position components are across multiple chunks/much apart from each other... wouldn't it loose the performance part everyone talks about due to components not being linear in memory?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    While the Position components may be spread across multiple chunks because there are so many, they are grouped in batches linearly inside each chunk. There is a little bit of a performance cost with jumping between chunks, but most of the linear memory gains remain valid.
     
  3. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    Thanks for the answer, but what do you mean by this and how can it be faster than having a NativeArray<Position> and NativeArray<int> PositionIndexesToTranslate.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Let's say that each chunk has a max capacity of 100 entities.
    Chunk A will hold an array of 100 positions and an array of 100 translations. Chunk B will hold an array of 100 positions. Chunk C will also hold an array of 100 positions...