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]>
Sunday, January 16, 2011, 1:09:20 AM, Daniel Henrique Alves Lima wrote:

>         Daniel, the tests are running the following template 10.000 times:
>
> [#ftl/]
> <html>
>   <head>
>     <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />>
>     [#assign  entityName][@g.message code="test1.label"
> default="Test1" /][/#assign]
>     [#assign  entityName][@g.message code="test1.label"
> default="Test1" /][/#assign]
>     [#assign  entityName][@g.message code="test1.label"
> default="Test1" /][/#assign]
>     <!-- ${entityName} -->
>   </head>
> </html>
>
>         It takes 20-30 seconds. GSP is doing something equivalent in 4-6
> seconds, but this doesn't make any sense: Save a minor overhead, they
> are both calling the same compiled code to get the job done.

Well, it looks like a micro-benchmark, so everything is possible. I
mean, what does g.message do? If almost nothing, like only a
HashMap.get, then it's easily possible to get a 5x slowdown figure.
Like, you are *capturing* output here, which involves collecting into
a StringBuffer, which is much much slower than assigning the result of
an expression to variable (like [#assign entityName =
g.message(...)]). Plus you might have a startup overhead (especially
if you have auto-#import) that can be comparable to the actual
execution time of the template. So on, so on... Actually, if you are
going to assemble Web pages from hundreds of little independent
templates (i.e., you call cfg.getTemplate(...).process(...) for each
of them), I don't think FreeMarker fits the task.

>         Something is very odd, but to me FreeMarker doesn't seem the root of
> the problem (i really need a better profiler :-/):
>
> http://grails.1312388.n4.nabble.com/FreeMarker-vs-GSP-for-Dynamic-Template-Rendering-tp3213939p3219595.html
>
>
>         Thanks!
>
>
> On Sat, 2011-01-15 at 21:22 -0200, Daniel Henrique Alves Lima wrote:
>>       Hi, Daniel.
>> 
>>       I'm not sure (yet). I believe FreeMarker performance should be close to
>> GSP performance in this case. FreeMarker is performing worse by a large
>> factor. I'm trying to discover if Tags plugin has something to do with
>> it.
>> 
>>       Thanks.
>> 
>
>
>

-- 
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.