jreijn / spring-comparing-template-engines

Demo project to show different Java templating engines in combination with Spring MVC
Apache License 2.0
422 stars 116 forks source link

Improving Thymeleaf results #1

Closed danielfernandez closed 10 years ago

danielfernandez commented 10 years ago

At first sight, there are a couple of modifications you can do in order to improve your Thymeleaf results.

Time taken for tests:   10.756 seconds
Time taken for tests:   8.159 seconds
Time taken for tests:   5.394 seconds

Thanks for the figures! I will tell you if I find further points of improvement.

jreijn commented 10 years ago

Thank you so much for the comment and improvements! I've tried to incorporate all your feedback and I've also switched to using ApacheBench, which seemed to give even better results (not sure why yet), but still Thymeleaf is a bit slower on my 2009 Macbook Pro then the rest. Since most of this is CPU bound I guess, the time will be a lot less on faster machines. I assume that Thymeaf is a bit slower then the rest, mostly because of it being DOM based.

I've updated the README as well. Before doing the measurements I always did at least 2 dry runs with the same configuration as I would do to measure the results. The average number of seconds is measured over 5 consecutive runs.

I must have read over the ConditionalCommentsDialect. It seems indeed that it was not necessary to have the dependency and the additional overhead within the templates.

In general my view of Thymeleaf is that it's a great template engine. It's still young, but adds tremendous value for Java developers working on web applications.

danielfernandez commented 10 years ago

Yup, Thymeleaf is slower than (at least) JSP, Velocity and FreeMarker, I can confirm that.

From our perspective, it is a technology of a different nature (markup-conscious template engine vs. text processor), and allows developers to work at a slightly higher level. So trading a bit of performance at the view layer --which normally takes only a tiny % of the execution time of web applications-- in exchange for a better development and maintenance experience usually looks like a good deal. It's a bit what you do when you use Hibernate instead of coding JDBC queries, for example.

The updated figures in your README look feasible to me. We normally see a 2x-3x increase compared to JSP, though this depends a lot on the specific scenario. My worries were more focused on the comparison chart in your presentation here http://es.slideshare.net/jreijn/comparing-templateenginesjvm, which show an approx 6x increase compared to JSP and looked really weird to my eye. Maybe you were not using Spring there? when not in a Spring environment, thymeleaf uses OGNL instead of SpringEL, and OGNL is much slower executing expressions...

Anyway, in case you are interested, we are planning to mostly rewrite our parsing and DOM processing system for Thymeleaf 3.0, with the aim of (among other things) improving performance.

jreijn commented 10 years ago

In my presentation I was using the results coming from this specific application with Spring MVC. I tried to keep the examples as close as possible together, so they all use i18n, fragments, iteration, etc.

My personal perspective is that Thymeleaf is not that much slower. Maybe it looks this way from the slidedeck, but if you look closely at the slide with the chart you might see it starts at 12.50 seconds and not at 0. I thought this made it a bit more clear what the difference was between Freemarker, Velocity, JSP and Mustache, since they were very close to each other. I explained this during my talk, but it might be easy to overlook from the slidedeck.

I really like the way Thymeleaf works and I will keep a very close eye on Thymeleaf as a replacement of Freemarker or JSP as the view technology used by Hippo CMS. I will definitely keep an eye on what's going on with Thymeleaf 3.0