Thymeleaf performance

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Thymeleaf performance

salbob
I saw that thymeleaf has horrible performance according to this benchmark. Anyone can confirm ? It was run with version 2.1.4.RELEASE. I tried with version 3.0.0.BETA01 and got like 2500 ops/sec which is way behind the others.

Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

Zemi
Administrator
Hello,

Thymeleaf performace is quite good for the most common web applications but performed worse in some specific cases. Thymeleaf 3 fixes most of those cases.

Performance is not only about rendering time, but memory footprint and not blocking concurrent threads.

According to the chart you published, it takes 1 ms to render one template, I would not call that horrible performance. Is it too much for your application?

Kind regards,
   Zemi

Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

salbob
The template is really simple, an html table outputting 20 rows. But the others template engine are like 20-30 times faster.

Just wondering why this huge difference with others template engine.
Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

danielfernandez
Administrator
In reply to this post by salbob
Hello salbob,

Could you point me to the source code of that benchmark? Any github repos or similar?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

salbob
Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

danielfernandez
Administrator
OK, I know that benchmark. The author is the author of the Pebble template engine.

It thoroughly uses th:utext (unescaped text), which is good news for some other template engines because they don't have to escape anything, but bad news for an HTML-parsing-based template engine like Thymeleaf. Actually, using th:utext in those cases is not a great idea (you would expect normal text in tables to be escaped, not unescaped), so a much more adequate way of executing that benchmark is modifying all template engines to use escaped output.

Also, in order to be fair those "th:href" should be real link expressions, with URL rewriting, etc. So in Thymeleaf they should be @{...} expressions. Unfortunately not all those template engines allow URL rewriting, at least out-of-the-box.

From then on, most part of the Thymeleaf execution time (close to 80%) is actually due to the underlying expression language, which in this case is OGNL because Spring support is not enabled. Using Spring would mean Thymeleaf using SpringEL instead of OGNL, which is noticeably faster. In any case, both OGNL and/or SpringEL are expression languages hugely more powerful than any of the expressions that can be used in the other template engines. That's one of the reasons why the Thymeleaf template looks more concise and, importantly, is correct, statically displayable HTML. You can just add some text inside those <td>'s and it will look real good when open on a browser.

There are many other things, like e.g. mustache computing its "negativeclass" and in fact its complete iteration items in Java code (because they cannot be computed as an expression on the template), etc. But a complete analysis of this benchmark is really difficult, as is reaching a 100% fair comparison among template engines of such hugely diverse natures. I myself like several of those others quite a lot, I must say (e.g. freemarker is great IMHO), and in the end it is just a matter of choosing the right tool depending on your needs. If your application depends really that much on view-layer performance, you should probably look elsewhere. Maybe even try static HTML output.

Thymeleaf has to be slower, even in 3.0. By architecture. But then Thymeleaf offers a set of capabilities, and especially a development experience that is very difficult to match with other template engines, especially in everything related to the way it deals with HTML as such, and not as mere text like most other engines do. For me it is a bit like comparing direct JDBC access with JPA. Yes, your app should be faster if you code all your queries manually using JDBC, but...

Regards,
Daniel.


Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

salbob
Thank you very much for your answer I appreciate :)
Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

tom.wang
In reply to this post by salbob
hey friend,just try 3.x

i have a page with 1 tree and  2 tables,one table contains 500 cells and the other contains 100 cells, and each cell contains about 30000 characters.

using 2.x the time of rendering is about 30s.

but in 3.x the time is 400ms.
Reply | Threaded
Open this post in threaded view
|

Re: Thymeleaf performance

salbob
Still waiting for thymeleaf layout dialect 3.0 :)