Slide 1

Slide 1 text

EE, FASTER Jacob Russell - devot:ee

Slide 2

Slide 2 text

Three Parts • Three parts to making sites fly: • Server choice and setup • Code and db optimization (HTML / CSS / JS / PHP) • ExpressionEngine Optimization

Slide 3

Slide 3 text

ExpressionEngine Optimization • Good Coding Practices • Caching Techniques • Add-ons

Slide 4

Slide 4 text

Tools Template Debugging Output Profiler

Slide 5

Slide 5 text

Problem Areas

Slide 6

Slide 6 text

Conditionals • Simple vs Complex Conditionals • Simple Conditionals execute logic BEFORE contents • Complex Conditionals execute logic AFTER contents

Slide 7

Slide 7 text

Is it Simple? • NO Else • NO And, Or, etc. • NO Late Parsing Variables • NO Nested complex if statements

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Exception • Embeds run AFTER complex conditionals • If a complex conditional must be used, embed may speed it up • Still has downsides of an embed

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Loops • Loops are powerful, but also dangerous • Channel Entries, Channel Categories, Matrix Output • Remember that the code repeats for each result

Slide 13

Slide 13 text

Nested Loops • Channel Entries inside Channel Categories • What if there’s an embed inside that? • Overhead increases exponentially.

Slide 14

Slide 14 text

Results {exp:channel:categories category_group="1"}{!-- Venues --} {exp:channel:entries channel="events" category="{category_id}"}

{title}

  • Attendees

  • {reverse_related_entries channel="people"}
  • {title}
  • {/reverse_related_entries}
{/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

Slide 15

Slide 15 text

Embeds • Great for organization and not repeating code • Bad for speed • Really, really bad for speed

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

How it Looks Index Handler Listing Single Entry Header Footer Sidebar Item Sidebar Item Sidebar Item Comments Page Top

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

Alternatives • Fewer Embeds • Repeating code means tougher maintenance, faster performance • Combine Embeds • PHP Requires • PHP must be on input • Other Options!

Slide 20

Slide 20 text

GLOBAL VARIABLES • User defined static content • Late Parsing (Can’t feed channel:entries) • Not very flexible

Slide 21

Slide 21 text

Other Variables • Fresh Variables • Low Variables • Powerful • Many Fieldtypes have been ported to Low Variables

Slide 22

Slide 22 text

SNIPPETS • New with EE2 • Part of the template they’re included in, not separate like an embed • Low Overhead! • Early Parsing

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Tag Caching • Stores each tag cache in a file, based off URI • Multiple file lookups per template • Unknown limit

Slide 27

Slide 27 text

Query Caching • Caches queries per URI • Limit of 150, then cleared • Other options available in MySQL

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Template Morsels • Caching Alternative • Replace embeds and complex global variables

Slide 30

Slide 30 text

Caching Options • Cache Refresh • On Template Change • On Channel Update • Time Expire

Slide 31

Slide 31 text

Thanks! @jacobrussell EE Podcast - Thursday, October 27 devot-ee.com Watch twitter for a possible expanded guide in the future (no promises!)