Re: Possible room for performance improvement when using TemplateDirectiveModel and TemplateMethodModelEx

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
You could avoid all the re-instantiations of the
DynamicTagLibDirective if you just put them into the Configuration as
a shared hash variable "g" (see setSharedVariable), which stores the
DynamicTagLibDirective objects. Thus these objects will be created
only once during the whole application life-cycle (when you set up the
Configuration object). Also then auto-importing is not needed. OTOH
then a "g" in the data-model will shadow the "g" shared variable. (To
work that around, you can also add "g" with an additional name, like
"grails_tags", so you can say <#assign g = grails_tags> in the
template, hence shadowing the clashing "g" in the data-model. More
tricky than an import, but then, this accident will also occur
rarely.)


Friday, January 14, 2011, 9:44:30 AM, Daniel Henrique Alves Lima wrote:

>         Hi, everybody.  
>
>         My context is Grails freemarker-tags plugin.
>         First a quick explanation about how the plugin works:
>
>         At the startup, the plugin
>         - Creates a MultipleTemplateLoader that contains a
> StringTemplateLoader;
>         - Collects all Grails TagLibs that share the same namespace (for
> instance "g" namespace);
>         - For each namespace, it creates a "namespace.ftl_suffix" (for our
> example, a "g.ftl" template) that contains lines like
>
> [#assign message
> ="org.codehaus.groovy.grails.plugins.freemarker.DynamicTagLibDirective"?new("g", "message")]
> [#assign _message
> ="org.codehaus.groovy.grails.plugins.freemarker.DynamicTagLibFunction"?new("g", "message")]
>         
>         (these DynamicTagLibXYZ are adapters that know how to locate and
> execute Grails TagLibs)
>
>         - The created templates are added to StringTemplateLoader and are
> marked, in Configuration object, to be "auto imported".
>
>
>         That is all.
>
>         Every time a .ftl is called, a lot of instances of
> DynamicTagLibDirective and DynamicTagLibFunction are created and
> everything works fine (most of the time ;-)). FreeMarker cache seems to
> be in use, as expected:
>
> 2011-01-14 06:32:01,604 [http-8080-4] DEBUG freemarker.cache  -
> g.ftl[en_US,UTF-8,parsed] using cached since
> freemarker.cache.StringTemplateLoader$StringTemplateSource@5c1eb57
> didn't change.
>
>
>         I've added options to turn off auto-import and to turn off function
> definitions.
>         Related to FreeMarker, is there any other performance improvement that
> i could/should consider? Is it possible to avoid some object creation?
>
>
>         Thanks in advance.
>
> http://code.google.com/p/grails-freemarker-tags-plugin/source/browse/
>
>

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.