Re: [SMARTY-DEV] code patches for speed

From: Date: Fri, 13 Jun 2003 06:12:50 +0000
Subject: Re: [SMARTY-DEV] code patches for speed
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1570@lists.php.net to get a copy of this message
On Thu, 2003-06-12 at 21:40, Paul Lockaby wrote: > Hi, > > I was looking through Smarty over the past few weeks to see if there is > some way that I could speed it up for my slow server and I noticed a few > things that could help do that. So I've included them in this email. > > First thing I noticed is that when comments are annihilated, they are > actually left as {**}, which then has to be parsed and broken up into > tags and read later on. Why not just remove them entirely from the > source so that they don't have to be parsed through and seperated? I've looked at that before, it has to do with error message line numbering and how comments affect them. I've looked at "fixing" this in the past, and will take a much greater effort than I first anticipated. > > Second thing I noticed is that in the _compile_tag function, the regular > expression pulls out the tag name, modifier, and argument and then > passes the original tag unparsed to _parse_var_props and then on to > _parse_var where it has the variable name, modifier and arguments pulled > out again. Wouldn't it be faster to pass the tag name and modifier and > arguments instead of pulling them out again? Parse all variables once > using one preg_match_all instead of each variable using a preg_match? I'm sure there are some things that could be optimized in this part of the parser, but since this only affects compile-time speed it probably hasn't been given as much attention as something that affects run-time speed. We accept patches though ;-) > > When expanding quoted text, the function could probably be cut down a > lot more with some implementation like this: > > preg_match_all('/(?:[^\\\]' . $this->_dvar_regexp . ')/', > substr($variable, 1, -1), $_expand); > $_expand = array_unique($_expand[0]); > foreach($_expand as $key => $value) { > $_expand[$key] = trim($value); > if (strpos($_expand[$key], '$') > 0) { > $_expand[$key] = substr($_expand[$key], strpos($_expand[$key], '$')); > } > } > $_result = $variable; > foreach($_expand as $value) { > $value = trim($value); > $_result = str_replace($value, '" . ' . > $this->_parse_variable($value) . ' . "', $_result); > } > return $_result; > > Where $variable is the variable that you are parsing. > > Anyway, like I said, since I was interested in speed, I took a look > through smarty and removed a whole ton of stuff that I never used and > managed to make a script that works between 5 and 10 times faster than > Smarty with force_compile = true and about twice as fast when using > compiling. If you want to check it out, I put it up here > http://www.paullockaby.com/templatey/ along with some brief > documentation describing the changes I made. I hope that this is useful! That is compile-time which is cool, but run-time speed is the crucial factor, speed that up ;-) Anyways, I'll take a look at this when I find some time :/ Monte

« previous php.smarty.dev (#1570) next »