It always helps to read and understand the syntax of the programming and templating languages that you use.
According to Joel Spoelsky, string operations are generally the most resource intensive functions.
Searching a string is comparable to a painter who is told to paint a yellow line on the road, but he leaves the paint bucket at the starting point. Each time he walks back to the bucket to re-dip his brush, the trip gets longer. If the line is only 20' long, this won't take too long. But if the line is 300' long, the rate of progress slows linearly with the distance.
Parsing strings unnecessarily slows down the rendering of your web page by the server. The longer the string, the more cpu time it takes to parse it.
In SMARTY tags, double quotes are parsed for variables, while single quotes are taken as a literal string.
So this:
{content block="Block Number 1" oneline="true" assign="block_1"}
requires three parse operations.
But this:
{content block='Block Number 1' oneline='true' assign='block_1'}
requires none.
The only time that you want to use double quotes in a smarty tag is when the string contains a variable reference such as this:
{assign var='pagetitle' value="This is the $page_alias page."}
Assuming the page alias is "home" the tag above will produce the following value in $pagetitle:
"This is the home page."
The CMSMS default templates that come with {cms_module module="something" template="somethingelse" etc.} will run faster if you convert them to single quotes.
Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
WHAT?????? You can't be serious! You can't really expect me to both read AND understand all that stuff!!!!!!kendo451 wrote: It always helps to read and understand...

For real, though - very nice tip!!
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
Source?kendo451 wrote: According to Joel Spoelsky, string operations are generally the most resource intensive functions.
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
Spolsky, Joel, "Joel on Software", Apress, 2004, Chapter 2, Back to Basics, "Shlemiel the Painter's Algorithm"
I paraphrased him a lot. But his basic argument is that algorithms that search strings generally take more time relative to length squared.
Smarty - Single vs. Double Quotes
The most direct statement of this issue is here, however they do not address the performance hit from using double quotes:
http://www.nusphere.com/php/templates_smarty_functions.htm
I paraphrased him a lot. But his basic argument is that algorithms that search strings generally take more time relative to length squared.
Smarty - Single vs. Double Quotes
The most direct statement of this issue is here, however they do not address the performance hit from using double quotes:
http://www.nusphere.com/php/templates_smarty_functions.htm
Smarty will recognize assigned variables embedded in "double quotes" so long as the variable name contains only numbers, letters, under_scores and brackets[]. See naming for more detail.
http://www.smarty.net/manual/en/language.syntax.quotes.php
Regardless, single quotes in SMARTY are not checked for variable substitution, but double quotes ARE. So, using single quotes simplifies your code, and uses less processing power, making it run faster, if only slightly.http://www.smarty.net/manual/en/language.function.include.phpCode: Select all
{* wont work as its single quotes ie no variable substitution *} {include file='$module.tpl'}
Last edited by kendo451 on Fri Dec 18, 2009 3:40 am, edited 1 time in total.
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
If you have page caching, this will not affect performance much. But for pages that are always dynamic, and get recompiled every time it does.
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
Very interesting thanks for sharing this
Re: Single versus Double Quotes in Smarty - How to Speed Up Your Site a Little
Very good tip indeed Kendo!, thanks! 
