Replacing include with include_once in Smarty::fetch()?

From: Date: Wed, 15 Sep 2004 23:59:20 +0000
Subject: Replacing include with include_once in Smarty::fetch()?
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2568@lists.php.net to get a copy of this message
Dear smarty-developers, I'm extending a mailing application to allow for sending HTML emails. I use Smarty as template engine to build personalized e-mail messages (Smarty outputs html as well as text mime parts). Right now, I'm doing some performance tests and have to call $smarty->fetch a few thousand times (once for every personalized e-mail being sent), which is a very realistic - if not even small - setup for my purposes. The problem is that the include($_smarty_compile_path) around line 1258 in Smarty.php makes up a huge share of total execution time and also consumes a lot of memory, although it just includes the same compiled template again and again. I could imagine that the PHP parser will analyze/precompile the file upon every inclusion? I'm not that familiar with PHP internals... As a quick experiment, I wrote a postfilter to add "<?php function foo(&$this) { ?>" and "<? } ?>" around the compiled template and changed Smarty::fetch() to "include_**once**(...); foo($this);". That way I could reduce the execution time spent in that code region to a fraction of 1/8th, memory consumption is reduced by about 3.5MB. I suppose that longer template code and more repetitions would even yield better improvements. I know that usually you would hardly fetch the same template repeatedly during the same request, so maybe that problem only occurs with my very specific setup. However, what do you think of automatically placing template code in a function body? The function name could be derived from the resource or file name. Note that this would require calling the function instead of just including the compiled template; however, as long as Smarty::fetch is the only section of code including templates, that should not be a problem. Any ideas what else might break? Possible benefits? Best regards, Matthias

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