Search Unity

Adding/Removing Tags Performance

Discussion in 'Entity Component System' started by LlamaFarmer42, May 9, 2019.

  1. LlamaFarmer42

    LlamaFarmer42

    Joined:
    Jul 19, 2013
    Posts:
    9
    What are the performance implications for adding/removing tags on an entity every frame (i.e. changing archetype)? Is there a point where it's worth set a component variable instead, and what are the factors involved (frequency, number of entities affected)?

    I've seen this mentioned as something to consider, but nothing concrete. Is it something to consider for the average game, or only if making something like the megacity demo?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    If you plan add / remove tag on same entity every frame, you are better to use variable of the component.

    But if you have for example 100k entities, adding / removing tag, can reduce number of entities iterations in the system (s), by filtering relevant entities. So you don't need iterate through all 100k, but only selected group of entities. Can be specially useful, if you don't need change tag state every frame.

    However, for few entities probably there wont be any much of differences, in which method you will choose.
    Surely you won't notice any impact.
    But for 1k, 10k, 100k most likely.
     
    Deleted User likes this.
  3. LlamaFarmer42

    LlamaFarmer42

    Joined:
    Jul 19, 2013
    Posts:
    9
    Thanks, that's a very handy rundown.
     
  4. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    I think I read that tags (empty components) actually wont cause the chunks to be regenerated?
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    I can not 100% confirm it, but I know, that empty tags are treated differently, than component with data.
    How much difference is between setting / removing tag vs setting value in component, I never tested.
    But both approaches can serv different needs.
     
  6. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    https://forum.unity.com/threads/tags-archetypes-chunks.667429/#post-4467040
     
    Antypodish likes this.
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    siggigg likes this.
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    siggigg likes this.
  9. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    For more details about Tag ComponentData see this blog.
    you can find some benchmarks and Explanations about what's happening under the hood.
     
    eterlan, RaL, LlamaFarmer42 and 2 others like this.
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Thx for this reference.
    Blog is exactly, what I was highlighting for long time.
    Only that, I had no benchmark.
    But no need rocket scientist here ;)
     
    Opeth001 likes this.
  11. LlamaFarmer42

    LlamaFarmer42

    Joined:
    Jul 19, 2013
    Posts:
    9
    Some great info. That blog is super useful!
     
    Opeth001 likes this.