Adding/Removing Tags Performance

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?

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.

1 Like

Thanks, that’s a very handy rundown.

I think I read that tags (empty components) actually wont cause the chunks to be regenerated?

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.

https://discussions.unity.com/t/740871/2

1 Like

Thx for updated info with reference.
My knowledge was archaic, from mid 2018. :slight_smile: But never could find original source again, even tried to search for it.

1 Like

It’s only about group overload without cost. Per entity tag swapping still have cost, but anyway it faster than non zero sized :slight_smile:

1 Like

For more details about Tag ComponentData see this blog.
you can find some benchmarks and Explanations about what’s happening under the hood.

5 Likes

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 :wink:

1 Like

Some great info. That blog is super useful!

1 Like