Number of "sensor" entities: how often a template is evaluated

Assume we need to calculate a number of “sensor” entities:

template:
  - sensor:
      - name: xxx
        state: >-
          {{ states.sensor | list | length }}

The template is evaluated not often than once a second.

But when exactly it is evaluated?
After every change of any sensor?
After adding/removing a sensor only?

Asking because I am thinking about moving this into smth like

template:
  - trigger:
      time pattern or a user-defined event (raised by automation)
    sensor:
      - name: xxx
        state: >-
          {{ states.sensor | list | length }}

It says

If the template accesses all states under a specific domain, a rate limit of one update per second is applied.

So that’s your answer, once a second.

This is not what I asked.
My question was - what makes the template to be evaluated?
If it is evaluated on every change (state changed form “1” to “2”) - then this is too often and undesired.

The fact that used states.sensor is what triggers it to be re-evaluated. Though I am a little confused by that other bit of the docs that says

When merely counting states, the template is only re-rendered when a state is added or removed from the system.

I don’t know if that means that it only COUNTS the total number of states under that domain, or if it means every state change. I guess that it means it only COUNTS the number, and that won’t be re-evaluated unless a new state is added or removed. The thing that makes it confusing is do they mean state as in new data, or do they mean state as in the actual entity itself.

EDIT:
I am basing the assumption that it means entities themselves rather than the states of those entities - because it says when they are added or removed, and states are not removed, they are only updated. Entities are added and removed.

This is exactly why I posted this thread.
Evaluating the template on every change is not needed in my case - I am only interested to know a number of entities.

Would be great to get a clear confirmation.

So, this is open:

But I do not think that these templates are triggered differently:

{{ states.sensor | list | length }}
{{ states.sensor | selectattr(...)  and so on }}

where the 2ns template is definitely triggered after every change of any entity.