Body: <p>i have a big problem on my site. One for loop requires more than 30 seconds. When i put the loop in a comment, the page loads shortly. So the loop must be the problem.</p>
  
  <p>Is there any trick to accelerate a loop?</p>
  
  <p>Here is the loop code: </p>
  
  <pre><code>{% for program in craft.entries.section('program_point').order('program_number') %}
      {% if program.block.first().title == program_block.title %}
          &lt;div class="seminar-box"&gt;
              {% if program.type == "seminar" %}&lt;a href="{{ program.url }}"&gt;{% endif %}
              &lt;h4&gt;&lt;span&gt;{% if program.type != "seminar" %}#{% endif %}{{ program.program_number }}&lt;/span&gt;{{ program.title }}&lt;/h4&gt;
              {% if program.short_description|length %}
                  &lt;p&gt;{{ program.short_description }}&lt;/p&gt;
              {% endif %}
              {% if program.type == "seminar" %}&lt;/a&gt;{% endif %}
              {% if program.program_referents|length %}
                  &lt;span&gt;
                      {% set i = 1 %}
                      {% for referent in program.program_referents %}
                          &lt;!-- &lt;a href="{{ referent.url }}" class="referent-link"&gt;--&gt; {{ referent.referent_name }}&lt;!--&lt;/a&gt;--&gt; {% if i != program.program_referents|length %}, {% endif %}
                          {% set i = i+1 %}
                      {% endfor %}
                  &lt;/span&gt;
              {% endif %}
          &lt;/div&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-13T21:10:12.237Z
Comments.Text: Could you post the loop code? As you'd say it's likely something in there, but it will be pretty hard to comment on without the code ;)
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-13T21:19:45.330Z
Comments.Text: Great thanks - could you try commenting out the inner for loop? The one looping over `program.program_referents`.
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-13T21:49:23.010Z
Comments.Text: this requires nearly the some time
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T02:52:43.570Z
Comments.Text: Not sure if this is the cause of the speed issue, but you can remove the variable ```i``` and use twig's built in ```loop.index``` and ```loop.last```
  
  http://twig.sensiolabs.org/doc/tags/for.html
Comments.UserDisplayName: j00lz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T02:54:55.833Z
Comments.Text: Also try wrapping the inner loop in cache tags: ```{% cache %}<!-- your loop here -->{% endcache %}
Comments.UserDisplayName: j00lz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T05:35:30.600Z
Comments.Text: In which case it must be the outer loop - perhaps try adding a limit? However, I would try removing all the code inside the loop first to see if any of that is causing the issue and work outwards from there.
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T07:13:08.427Z
Comments.Text: now i have comment out all inside the loop and it takes 7 sec to load. 
  with the first if query it takes nearly 30 sec. So the first if might be the problem. Any idea why?
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T07:24:41.360Z
Comments.Text: @j00lz {%cache%} is a great idea, but then the if-query '{% if program.type == "seminar" %}' does not work. An idea why?
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T07:41:04.287Z
Comments.Text: are you sure? cache should not effect that at all...
Comments.UserDisplayName: j00lz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T08:40:47.907Z
Comments.Text: @j00lz yes i'm realy sure
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T09:48:22.893Z
Comments.Text: @JonathanSchiffner right - by commenting out the inside of the loop you are determining that it is definitely something inside there, so add things back in line by line until you hit the part that adds the extra 20s. Then you have found the actual problem and can work on solving that. For example: comment out everything inside that first `{% if %}` statement and see what difference that makes.
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T12:24:46.780Z
Comments.Text: is it possible to load first the html content and than the craft loop?
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-14T14:18:17.147Z
Comments.Text: I'm not sure what you mean.
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-30T17:02:58.040Z
Comments.Text: a new try:
  i only use this loop: `{% for program in craft.entries.section('program_point').order('program_number') %}` and it takes 25s . The loop returns 81 data. Any idea how to fix this problem?
Comments.UserDisplayName: Jonathan Schiffner
Tags: <templating><performance>
Title: TTBF about 30 seconds
ThreadText: # TTBF about 30 seconds
  
  (Asked by: username_0 on 2015-08-13)
  
  i have a big problem on my site. One for loop requires more than 30 seconds. When i put the loop in a comment, the page loads shortly. So the loop must be the problem.
  
  Is there any trick to accelerate a loop?
  
  Here is the loop code:
  
  ```
  {% for program in craft.entries.section('program_point').order('program_number') %}
      {% if program.block.first().title == program_block.title %}
          <div class="seminar-box">
              {% if program.type == "seminar" %}<a href="{{ program.url }}">{% endif %}
              <h4><span>{% if program.type != "seminar" %}#{% endif %}{{ program.program_number }}</span>{{ program.title }}</h4>
              {% if program.short_description|length %}
                  <p>{{ program.short_description }}</p>
              {% endif %}
              {% if program.type == "seminar" %}</a>{% endif %}
              {% if program.program_referents|length %}
                  <span>
                      {% set i = 1 %}
                      {% for referent in program.program_referents %}
                          <!-- <a href="{{ referent.url }}" class="referent-link">--> {{ referent.referent_name }}<!--</a>--> {% if i != program.program_referents|length %}, {% endif %}
                          {% set i = i+1 %}
                      {% endfor %}
                  </span>
              {% endif %}
          </div>
      {% endif %}
  {% endfor %}
  
  ```
  
  **Tags:** templating, performance
  
  > **Comments:**
  > **username_1**: Could you post the loop code? As you'd say it's likely something in there, but it will be pretty hard to comment on without the code ;)  
  > **username_1**: Great thanks - could you try commenting out the inner for loop? The one looping over `program.program_referents`.  
  > **username_0**: this requires nearly the some time  
  > **username_2**: Not sure if this is the cause of the speed issue, but you can remove the variable ```i``` and use twig's built in ```loop.index``` and ```loop.last```  http://twig.sensiolabs.org/doc/tags/for.html  
  > **username_2**: Also try wrapping the inner loop in cache tags: ```{% cache %}<!-- your loop here -->{% endcache %}  
  > **username_1**: In which case it must be the outer loop - perhaps try adding a limit? However, I would try removing all the code inside the loop first to see if any of that is causing the issue and work outwards from there.  
  > **username_0**: now i have comment out all inside the loop and it takes 7 sec to load.  with the first if query it takes nearly 30 sec. So the first if might be the problem. Any idea why?  
  > **username_0**: @username_2 {%cache%} is a great idea, but then the if-query '{% if program.type == "seminar" %}' does not work. An idea why?  
  > **username_2**: are you sure? cache should not effect that at all...  
  > **username_0**: @username_2 yes i'm realy sure  
  > **username_1**: @username_0 right - by commenting out the inside of the loop you are determining that it is definitely something inside there, so add things back in line by line until you hit the part that adds the extra 20s. Then you have found the actual problem and can work on solving that. For example: comment out everything inside that first `{% if %}` statement and see what difference that makes.  
  > **username_0**: is it possible to load first the html content and than the craft loop?  
  > **username_1**: I'm not sure what you mean.  
  > **username_0**: a new try: i only use this loop: `{% for program in craft.entries.section('program_point').order('program_number') %}` and it takes 25s . The loop returns 81 data. Any idea how to fix this problem?  
  
  ---
  
  ## 0 answers
  
  