Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Which is method is processed faster?

July 22, 2010 11:37pm

Subscribe [5]
  • #1 / Jul 22, 2010 11:37pm

    Blair L's avatar

    Blair L

    106 posts

    Somewhere on here awhile ago I read that using this:

    {if bla}
    Bla!
    {/if}
    
    {if no bla}
    No Bla!
    {/if]

    ...was faster than ...

    {if bla)
    Bla!
    {if:else}
    No Bla!
    {/if}

    Is that true with EE?

    Along that line, is the script processed faster to use the faster conditional above or a relationship, when caching is involved?  Example:

    A custom dropdown has the values “cherry” or “orange,”

    {exp:channel:entries channel="MyBlog"}
      {if custom_field_dropdown=="cherry"} Traverse City! {/if}
      {if custom_field_dropdown=="orange"} Florida! {/if}
    {/exp:channel:entries}

    or a second channel “food” is made with entries “cherry” and “orange” with a body tag that says “Traverse City” and “Florida” and a relationship custom field is placed in “MyBlog” to “food”.

    {exp:channel:entries channel="food" cache="yes" refresh="999"}
      {related_entries id="custom_field_dropdown"}
        {body}!
      {/related_entries}
    {/exp:channel:entries}


    Remembered an article written about EE’s features page where it quicker renderings were achieved by some relationship concept.

  • #2 / Jul 23, 2010 2:45am

    John Henry Donovan's avatar

    John Henry Donovan

    12340 posts

    Blair L,

    With conditionals it is mainly a question of Parse order. So a simple one may complete before it gets to completing an advanced conditional. So not necessarily speed.

    You can do your own speeds tests by flicking on your Display Template Debugging? under Output and Debugging

  • #3 / Jul 23, 2010 2:57am

    Blair L's avatar

    Blair L

    106 posts

    But in those specific examples, which theoretically should be quicker?

  • #4 / Jul 23, 2010 10:31am

    Ingmar Greil's avatar

    Ingmar Greil

    29243 posts

    I am afraid you would have to test it. There are too many sever-specific variables for a hard and fast rule.

  • #5 / Jul 24, 2010 1:36pm

    Kurt Deutscher's avatar

    Kurt Deutscher

    802 posts

    Hi Blair,

    {if logged_in_group_id == '1'}
         {total_queries} Total Queries
    {memory_usage} of Memory
    {elapsed_time} Seconds to Load
    {/if}

    We “speed test” every site we build while we’re building it. With EE 2.1.x you can add the above code to your site (I think the memory_usage tag is new to EE 2), and assuming you are a Super Admin (group_id 1), you should see these three measures of how your code is performing.

    One concept to grasp about simple conditionals vs. advanced is that advanced parse really late during the page load and after the channel tags do. I’ve seen a lot of EE developers kill their speed by coding something like this in a template:

    {if this_condition}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {if:elseif another_condition}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {if:else}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {/if}

    Since the advanced conditionals parse AFTER the channel tags, EE runs all three channel tags every time the template loads, even though it will only display the results of one of them. It basically buys three pairs of shoes even though it can only ware one pair at a time. If any of those channel tags has the ability to return lots of entries, then you can run into issues.

    {if this_condition}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {/if}
    {if another_condition}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {/if}
    {if things != "this_condition" AND things != "another_condition"}
         {exp:channel:entries}
              {content}
         {/exp:channel:entries}
    {/if}

    Using simple conditionals that parse BEFORE the channel tags do, EE should only have to run one of the three channel tags per template load. if you have well-formed simple conditionals

    Hope this helps you a bit in you quest for speed.

    **Update: Take note of the last conditional, which is actually considered to be advanced by later builds of EE. So my final example uses two simple conditionals and one advanced. See this great post for more info on the subject: http://ellislab.com/forums/viewthread/168268/

  • #6 / Jul 24, 2010 5:17pm

    Greg Salt's avatar

    Greg Salt

    3988 posts

    @Kurt, thanks very much. Nice write up!

    @Blair L, does that help you out?

    Cheers

    Greg

  • #7 / Jul 24, 2010 8:59pm

    Blair L's avatar

    Blair L

    106 posts

    There we go… That exactly what I was looking for!

    ... and it look me awhile, but this was the other question I was looking for http://ellislab.com/blog/entry/behind_the_curtain_part_four/

  • #8 / Jul 25, 2010 4:16pm

    Greg Salt's avatar

    Greg Salt

    3988 posts

    Hi Blair,

    Excellent. Glad Kurt’s explanation helped sort that out. Please post back if you have further questions or problems.

    Cheers

    Greg

ExpressionEngine News

#eecms, #events, #releases