Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EE, Faster

EE, Faster

Presented at the 2011 ExpressionEngine and CodeIgniter Conference in Brooklyn, New York. This talk is an overview on the common causes of slow load times in ExpressionEngine sits and how you can overcome them. The goal of this talk was to get listeners on the right track in diagnosing their site issues and researching further on their own.

Jacob Russell

October 24, 2011
Tweet

Other Decks in Programming

Transcript

  1. Three Parts • Three parts to making sites fly: •

    Server choice and setup • Code and db optimization (HTML / CSS / JS / PHP) • ExpressionEngine Optimization
  2. Conditionals • Simple vs Complex Conditionals • Simple Conditionals execute

    logic BEFORE contents • Complex Conditionals execute logic AFTER contents
  3. Is it Simple? • NO Else • NO And, Or,

    etc. • NO Late Parsing Variables • NO Nested complex if statements
  4. Consider • Pages with large amounts of logic split by

    a complex if will run ALL the logic • Can lead to a lot of excess overhead • Templates that handle both listing and single entry are a common cause
  5. Exception • Embeds run AFTER complex conditionals • If a

    complex conditional must be used, embed may speed it up • Still has downsides of an embed
  6. Alternatives • PHP If • With PHP on input, if

    statements can be used properly • Must have PHP turned on, ‘on output’ no longer available • Add-ons
  7. Add-ons • Switchee • Brings PHP’s switch case logic into

    EE • Parse=”inward” avoids unwanted code • Not optimal for all logic situations • IfElse • Early parsing with If statements • Both from Mark Croxton
  8. Loops • Loops are powerful, but also dangerous • Channel

    Entries, Channel Categories, Matrix Output • Remember that the code repeats for each result
  9. Nested Loops • Channel Entries inside Channel Categories • What

    if there’s an embed inside that? • Overhead increases exponentially.
  10. Results {exp:channel:categories category_group="1"}{!-- Venues --} {exp:channel:entries channel="events" category="{category_id}"} <h1>{title}</h1> <ul>

    <li><h2>Attendees</h2></li> {reverse_related_entries channel="people"} <li>{title}</li> {/reverse_related_entries} </ul> {/exp:channel:entries} {/exp:channel:categories} 10 Venues, 20 Events and 40 People = 8,000 Iterations 20 Venues, 160 Events and 1100 People = 3,520,000 Iterations
  11. Embeds • Great for organization and not repeating code •

    Bad for speed • Really, really bad for speed
  12. How they Parse • Second to last in parse order

    • Followed only by global vars and a small list of other vars • Each embed runs like a new page, restarting the template engine
  13. How it Looks Index Handler Listing Single Entry Header Footer

    Sidebar Item Sidebar Item Sidebar Item Comments Page Top
  14. Result • Loading a single entry page runs the template

    engine 10 times • Loading a listing page runs it 6 times • To get to an entry page from a listing is like loading 16 separate pages.
  15. Alternatives • Fewer Embeds • Repeating code means tougher maintenance,

    faster performance • Combine Embeds • PHP Requires • PHP must be on input • Other Options!
  16. GLOBAL VARIABLES • User defined static content • Late Parsing

    (Can’t feed channel:entries) • Not very flexible
  17. Other Variables • Fresh Variables • Low Variables • Powerful

    • Many Fieldtypes have been ported to Low Variables
  18. SNIPPETS • New with EE2 • Part of the template

    they’re included in, not separate like an embed • Low Overhead! • Early Parsing
  19. Caching • Template, Tag, and Query Caching • Stores a

    cached copy for each URI in a file • Limits db traffic in favor of a file-system lookup
  20. Template vs Tag • Template usually the better choice •

    Larger scope means fewer separate caches • Tag caching makes sense when you can only cache a small part of a page • Helps avoid logged in/logged out conditionals
  21. Template Caching • Renders a whole page, stores it as

    a flat file for specified time • Limit of 1000 files • When limit reached, cache clears and starts over
  22. Tag Caching • Stores each tag cache in a file,

    based off URI • Multiple file lookups per template • Unknown limit
  23. Query Caching • Caches queries per URI • Limit of

    150, then cleared • Other options available in MySQL
  24. Consider • Site Structure • More URI’s means more cache

    files, hit limit faster • Fewer URI’s mean longer cache times • Faster? • Simple Pages may be faster without caching • EngineHosting tuned for fast db lookups
  25. Thanks! @jacobrussell EE Podcast - Thursday, October 27 devot-ee.com Watch

    twitter for a possible expanded guide in the future (no promises!)