[Templates] TT Speed Question

Andy Wardley abw@andywardley.com
Wed, 8 Jan 2003 15:44:18 +0000


Brian Hann quoted a colleague:
> Template Toolkit is a fine thing but it is horribly slow. [...]
> It only has acceptable times with mod_perl. 

I don't know about "horribly", but yes, TT is designed primarily to be a 
comprehensive template solution, not just the fastest.

If speed is a concern then, yes, you absolutely have to use it under 
mod_perl.  But that is probably true of any template module.  If you're
using CGI then you probably don't care about performance.

The mod_perl benchmarks show that TT is a little slower than other solutions,
but not always the slowest.  That would seem right to me.  Accessing a 
variable in TT requires you to make a method call to the stash, whereas
other template engines access variables direct.  For that reason, TT will 
always be a little sluggish compared to pure Perl solution.

There are ways to speed this up if you really want to.  Compile time 
constant folding allows you to eliminate a significant amount of overhead
in many cases by eliminating variable lookups at compile time.  

Also, the XS stash certainly should help to make things
faster.  If the benchmarks don't show a speedup with the XS stash then 
maybe the benchmarks are flawed?  It may be the case that what he's 
really measuring is how long it takes TT to compile and execute the 
template, not just to execute it.

If you switch the COMPILE_EXT option on and pre-compile all templates then 
things might run a lot faster.

> What do you think, does this have any validity?

Only if the Template Toolkit is too slow - but I haven't yet heard of a 
web site that couldn't use TT because it was too slow.  There are usually
plenty of other bottlenecks that you need to worry about before the 
performance of your template engine becomes an issue.

Far more important, IMHO, is development and maintenance productivity.
It's easy to bang the hardware hammer to make a server run faster.  It's
not so easy to make your programmers deliver the system sooner.


A