GetNumberOfInstances is implemented using the EntityIterator, which causes the performance to degrade severely when there are many instances.
The reason for using the iterator is that we need to be sure of only counting Real states (no ghosts or downgraded states), so we can't just use the size() function on the instance container.
Either it may be possible to create a better way of counting instances, or maybe we should introduce a function that just uses size(), and provides an "estimate", rather than an absolute value.
Or should we introduce counters for each entity type?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some info from an old Trac ticket: