EE2 - Snippets and performance issues
Posted: 06 May 2010 05:33 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  51
Joined  04-05-2010

I’m trying to optimize a site. We’ve moved it to a (dv) with Mediatemple, so it’s using a local MySQL. Everything runs instantaneously with caching (as it should), without it there is a minimum of 1 second latency even when the template has only one word (is static, but not cached).

According to the debug, the longest time (over 95% of the latency) is spent on the step:
Controller Execution Time
and more specifically:
Parsing Segment, Embed, and Global Vars Conditionals

SO my question is this: Are Snippets parsed even when the page is not using them? We have some rather beefy snippets, and this would explain some things. If this is the case I can simply move those into their own embeds.

Profile
 
 
Posted: 07 May 2010 12:45 AM   [ Ignore ]   [ # 1 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  14993
Joined  03-22-2004

LWT CONNECT,

In your Output and Debugging preferences, switch on your Display Template Debugging?. This will tell you exactly what is going into building that template.

Admin -> System Administration -> Output and Debugging

Profile
 
 
Posted: 07 May 2010 04:01 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  730
Joined  11-11-2006

SO my question is this: Are Snippets parsed even when the page is not using them? We have some rather beefy snippets, and this would explain some things. If this is the case I can simply move those into their own embeds.

Yes.

Profile
 
 
Posted: 07 May 2010 09:11 AM   [ Ignore ]   [ # 3 ]  
Chancellor's Fellow
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33338
Joined  05-15-2004

Does that help, LWT CONNECT? I, too, would suggest to use embedded templates in your case.

Profile
MSG
 
 
Posted: 07 May 2010 11:15 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  51
Joined  04-05-2010
leeaston - 07 May 2010 08:01 AM

Yes.

Thanks, we’ll try to avoid using them except when necessary from now on.

EDIT: I’ve been removing snippets and it seems that even the CP is loading pages considerably faster…

Why on earth do snippets need to be parsed when in the CP? Seems a waste of resources.

Profile
 
 
Posted: 07 May 2010 11:21 AM   [ Ignore ]   [ # 5 ]  
Chancellor's Fellow
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33338
Joined  05-15-2004

Glad to see that cleared it up for you. Please post again as needed.

Profile
MSG
 
 
Posted: 07 May 2010 03:52 PM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  26092
Joined  05-14-2004

I wanted to re-open this to help clarify how snippets works.

In brief:  They are always loaded on the front-end when assigned to the Site being viewed.  They are not always evaluated.

The magic, as it were, occurs in the template library.  You load a page and a single query gets all the snippets.  The snippets are merged into the global variables array.

Then a find and replace occurs for the snippet name.  Even if you have embeds in your template, there is only one query to grab the snippets. 

In terms of queries and evals, there is not that much of a hit.  If you had an extremely large number of very complex snippets, you might see some extra memory usage; but there’s not all that much code going on here, it’s basically a find and replace.

If you took the exact same large number of complex snippets and turned them into embeds, you would see a much heavier hit.

This is why we recommend Snippets over Embeds unless you need to do something such as pass variables.  Snippets are treated exactly as if that code was directly in the template, whereas embeds are treated as entirely separate entities.  Embeds are absolutely “heavier” than snippets.

Does that help?

[Edit to Add] To clarify what you see in the debugger, the list of snippet variables is put into memory, but each snippet is not run unless it’s in the template itself.

And one more clarification: Snippets should have no impact on the CP as they are not read or executed in the CP.

 Signature 
Profile
MSG
 
 
Posted: 11 May 2010 02:21 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  51
Joined  04-05-2010

Thanks Lisa, that helps clear things up a great deal.

In any case we are still having page loads of several seconds (with caching disabled)...

Even if a template is completely empty it still seems to be rather slow, reporting 0.4 - 2.4 seconds on the “Controller Execution Time” stage.

More specifically: “Parsing Segment, Embed, and Global Vars Conditionals” still takes the majority of such a page load (over 80%).

We’ve also noticed that when we use an ‘entries’ tag with sorting based on a custom date field this slows down things by several seconds (over using the built-in date field).

Is this a normal experience?
Would we see drastic improvement with EngineHosting?
Could there be a setting, extension/module/plugin2 that could slow things down like this?

Is there a document somewhere that I’ve missed that shares the finer points of fine-tuning EE for speed?
We’ve already read and applied http://expressionengine.com/wiki/Optimize_EE/

We will be using caching for the live site, but that is not going to be an option in some projects.

Any help would be greatly appreciated.

Profile
 
 
Posted: 11 May 2010 08:50 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRank
Total Posts:  6675
Joined  09-23-2009

LWT CONNECT,

Have you tried a clean install of EE2 on the same server to see if the lag occurs there too? If it does, that would point to a server issue.

 Signature 
Profile
MSG
 
 
Posted: 13 May 2010 11:38 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  11-29-2008

Hey guys, there’s a link to this thread from the Snippets page in the EE2 docs. I was hoping this thread might say something about how you actually create a snippet. There’s nothing I can see on the Docs page that explains this.

Profile
 
 
Posted: 14 May 2010 02:00 AM   [ Ignore ]   [ # 10 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  14993
Joined  03-22-2004

ralph.m,

You can find Snippets here

Design -> Templates -> Snippets

When you create a snippet it gives you the correct syntax to use in your template. If you installed with the Agile theme you will see a lot of snippets created already for examples

Does that help?

Profile
 
 
Posted: 14 May 2010 03:54 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  11-29-2008

Thanks John, it does indeed help. Thanks for taking the time to reply. I do recommend that a note about this be included in the docs.

Profile
 
 
Posted: 14 May 2010 09:24 AM   [ Ignore ]   [ # 12 ]  
Chancellor's Fellow
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  30388
Joined  04-29-2002

ralph.m, you might want to consider putting in a Feature Request for a doc change.

Profile
MSG
 
 
Posted: 14 May 2010 09:49 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  11-29-2008

OK Sue, will do.

As an aside, I’ve just been reading up on relationships, and it was fantastic to have a scenario set to give this feature a context (the situation of The Night Club Owner). It would be great to have scenarios like this for all features, to help give them a context.

Profile
 
 
Posted: 14 May 2010 03:58 PM   [ Ignore ]   [ # 14 ]  
Chancellor's Fellow
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33338
Joined  05-15-2004

Looking forward to your FR, Ralph smile Where are you with this, LWT CONNECT?

Profile
MSG