[Templates] PROPOSAL: Allow CACHE_STR_REFS configuration item
Paul Seamons
mail@seamons.com
Wed, 13 Jun 2007 13:04:13 -0600
Because of the way Text::Tmpl functions, it must operate on filenames.
Therefore any stringref that is parsed is first saved to a file using
the md5 sum of the string. While writing to file isn't the best thing,
using the md5 sum is actually a performance improvement.
Template::Alloy provides the CACHE_STR_REFS configuration item which
defaults to true. It allows for stringrefs to use the same caching
mechanisms as normal files (both in memory and/or to filesystem).
It also works for eval'ed strings.
Taking the md5 sum is far less costly then parsing and evaluating the
string ref each time (the md5 sum method is 2-3 times faster in most
cases).
Some sample benchmark output can be found at the following url (the relevant
cases here would be TA_NOCACHE and TA under the string ref section):
http://search.cpan.org/~rhandom/Template-Alloy-1.002/samples/benchmark/bench_various_templaters.pl
Setting CACHE_STR_REFS to 0 would disable stringref caching.
This item probably could be added to TT2 without too much invasion,
though a code analysis hasn't been performed.
If implemented, passing in stringrefs or evaling strings can avoid
the penalty of parsing every time.
Paul Seamons