On Feb 16, 2006, at 4:20 PM, Perrin Harkins wrote:
On Thu, 2006-02-16 at 22:14 +0100, Daniel McBrearty wrote:
One question about the various template systems and mod_perl : is
there not a performance hit in using these?
and whatever the performance hit is - remember that 90% of your
processor time is spent on the page logic / DB interaction. if you
come across any major performance issues, you can try caching entire
pages, or parts of pages, into memcached or something similar to
avoid repetitive tasks.
after playing with templating systems for far too long - i offer this
golden piece of advice: use whatever templating system gives you the
best templates for your needs (be it natural writing or speed of
writing, or standards compliant, or easy to use by html monkeys).
the biggest performance gain to get with any templating engine is in
authoring the template itself .
If there is effectively perl code in the template which actually
changes with different pages that load, isn't mod_perl forced to
recompile the code for each request?
There are different pages for different templates, but once they have
been compiled they don't need to be loaded again. See my templating
article for more on how this works.
When I looked at all this a while back, I figured that this must be
the case, and went with CGI::FastTemplate as it uses pure regex
matching, I suspected it was likely to avoid this. Was I wrong? Is my
code actually quicker than it would have been with TT / Mason?
Probably slower. TT and Mason don't need to do any regexes because
they
have compiled the template to a perl sub. They don't have to parse
the
template at all after the first request in each process. Of course
they
have their own sources of overhead, but template parsing is not one of
them.
petal does the same thing, most of the templating systems also seem
to have their own caching mechanism somewhere as well.
i've found that most templating systems take an awful performance hit
when they compile the templates into perl subs. it would be nice if
every engine had a flag that let you specify if the template was
precompiled or not, and came with a tool to recursively precompile
template directories. but i can wait the extra 3 seconds on startup.
the only thing that i would suggest when using these under mod perl
is this: run something on startup that precompiles and caches all of
the templates just as it does to the perl modules/packages. i
realized a big memory killer in my Petal use was that templates were
being cached by ModPerl as accessed , instead of on startup. with
300k of html templates, that means that every 3 apache children
equate to 1mb of shared memory that i could have consolidated them into.