Search Unity

Feedback Archetype without entityId

Discussion in 'Entity Component System' started by JesOb, Apr 19, 2019.

  1. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Entity Id Consumes 8 bytes of data per record.
    For small entities 1-2 bytes in size this is big waste of space.

    Allow creation archetypes without EntityId in many cases we dont need to know EntityId from chunk iteration.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Under what circumstances would an this ever be an issue?

    You could create 1,000,000 empty entities and it'd only save 8MB of memory. Even in the most low end of hardware these days that is unlikely to be your bottleneck.
     
    Last edited: Apr 19, 2019
    Opeth001 likes this.
  3. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Potentially I can have world with 8M entities mostly static, 4 bytes each so it is 32MB of data

    With entityId inside archetype it will be 96MB of data.

    While it is not big deal for memory itself it will cost a performance to process because all 96MB will be loaded into caches :)

    May be I fear for nothing. This is just logical assumptions.
     
  4. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    105
    I think since the Chunks are layed out as struct of arrays and not as array of structs, the Entities should not be loaded into caches if you do not use them.
     
  5. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    They will not be loaded into processor cache line it is true. but they will be loaded to all other caches: l3 l2 l1
     
  6. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Could you explain this? My understanding was that the cache line size for all caches was only 64 bytes. Why would the whole 16kb be loaded into l2 and l3?

    In any event, I'm not sure you can actually leave out the Entity array in the chunk as the only way to retrieve it, when you do need it, is to search the entire Entity freelist which is inconceivable.
    The only perf cost involved is cache misses due to many more chunks but that can be got around down the track by having custom chunk sizes.
     
  7. BenzzzX

    BenzzzX

    Joined:
    Jun 4, 2018
    Posts:
    14
    You can't do it, EntityId's needed to remove entity from chunk.
    To be specific, removing entity from a chunk is done by removing at swapping back, and thus we should update the moved entity's chunk data, and that's why EntityId is needed.
     
    JesOb likes this.
  8. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    I have Google a bit to be sure about prefetchers and the only meaningful piece of info was:

    So not too much data will be accessed. Many cache misses on chunk boundaries may be the only real downside :)
     
  9. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Thanks that's very interesting. I always imagined the pre-fetch size would be such that it could feed L1 with no lag for streaming data.