Performance of a categories list with post count Let's say I'm outputting a list/nav of categories, with the count of entries in each category, as described in other questions:

{% nav category in craft.categories.group('...') %}
   {% set entryCount = craft.entries.relatedTo(category).total() %}
   {{ category.title}} ({{ entryCount }})
{% endnav %}


On a site with plenty of categories (more than 100 in this case), that seems like a lot of relatedTo queries. Is there a way I could accomplish the same thing with fewer queries / better performance?
I don't think you'll be able to avoid the database queries, but you'll definitely want to use cacheing here, and set a high cache time if possible.

Wrap your code in {% cache %} tags like below: 

{% cache globally for 1 month %}
{% nav category in craft.categories.group('...') %}
   {% set entryCount = craft.entries.relatedTo(category).total() %}
   {{ category.title}} ({{ entryCount }})
{% endnav %}
{% endcache %}


If this navigation appears on every page, use the "globally" tag.