Perrin Harkins wrote:
> It would work fine, but there is a performance penalty for using INCLUDE
> which many people are not aware of.  INCLUDE makes a complete copy of
> the Stash in order to give the included template a private copy of the
> data.  Most people don't need this, so INCLUDE is just wasting time and
> they should be using PROCESS.

That's another item from the "seemed like a great idea at the time" list 
that is fixed in TT3.   :-)

Rather than copying the entire variable stash each time we need to 
create a localised variable scope (e.g. INCLUDE), TT3 creates a new, 
empty variable stash with a parent link pointing upwards to the stash 
of the calling context.  

When a variable is first accessed, the stash fetches it from a parent, 
grandparent, great-grandparent, etc., walking up through the ancestral 
family tree until the variable is located.  It then copies it into the 
current local stash, effectively caching it for any subsequents access.  
Any new variable values are written into the local stash, leaving any 
previous values untouched in the parent, grandparent, etc.  At the end 
of the template, the local stash is throw away and we revert to the 
parent stash.

The same localisation mechanism is employed for all resources addressable
by TT3: variables, templates, plugins, filters, and any other custom 
resources you might like to add.  This has been unified in the all-new
singing and dancing Template::Context object, although I'm still in 
the process of unifying some of these parts right now, so the architecture
is fluxating somewhat.  

Cheers
A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to