How to improve performance of this nested entries/array template? I have an event calendar of sorts for music gigs. The back-end has sections for Artists and Venues, where I enter appropriate info, and another section, Shows, which I choose an artist, a venue, and enter the event date (in a custom field).

The template that pulls everything together grabs all future show dates, groups the dates by the artist, then checks each entry for fields before displaying it in the HTML, like so:

{#-- grab all current shows and order by date --#}
{% set all_shows = craft.entries.section('shows').gig_date('&gt;=' ~ (now.date)).order('gig_date asc') %}

{#-- group shows by artist --#}
{% set artist_shows = all_shows|group('gig_artist.first()') %}

{% for artist, shows in artist_shows %}

    {#-- artist title --#}
    &lt;h3&gt;{% if shows[0].gig_artist[0].artist_url|length %}&lt;a href="{{ shows[0].gig_artist[0].artist_url }}"&gt;{{ artist }}&lt;/a&gt;{% else %}{{ artist }}{% endif %}&lt;/h3&gt;

    &lt;table&gt;
        &lt;tbody&gt;

            {#-- shows list --#}
            {% for show in shows %}

                &lt;tr&gt;
                    &lt;td class="gig_date"&gt;

                        {#-- date --#}
                        &lt;time title="{{ show.gig_date.w3c }}"&gt;{{ show.gig_date|date('F j') }}&lt;/time&gt;
                    &lt;/td&gt;
                    &lt;td class="gig_venue"&gt;

                        {#-- venue name and website--#}
                        {% if show.gig_venue[0].venue_url|length %}&lt;a href="{{ show.gig_venue[0].venue_url }}"&gt;{{ show.gig_venue[0].title }}&lt;/a&gt;{% else %}{{ show.gig_venue[0].title }}{% endif %}

                        {#-- city --#}  
                        {% if show.gig_venue[0].venue_city|length %}, {{ show.gig_venue[0].venue_city }}{% endif %}

                        {#-- state --#}
                        {% if show.gig_venue[0].venue_state|length %} {{ show.gig_venue[0].venue_state }}{% endif %}

                        {#-- notes --#}
                        {% if show.gig_notes|length %}&lt;div class="gig_notes"&gt;{{ show.gig_notes }}&lt;/div&gt;{% endif %}
                    &lt;/td&gt;

                &lt;/tr&gt;

            {% endfor %}
        &lt;/tbody&gt;    
    &lt;/table&gt;

{% endfor %}


This page takes several seconds to render on my site versus the other pages. I've tried this without the |group filtering, and without the date comparison, and it's still equally slow, which leads me to believe it's the pinging the multiple entry fields that's slowing things down.

I have a hunch eager loading will be helpful, but unfortunately I can't wrap my brain around it at this level. Any ideas?
Have you considered to cache the whole output? https://craftcms.com/docs/templating/cache