2

I'm about to start in on a new Spring MVC project, and I'm examining the various options for the view. I've never been a fan of JSP, and I've run into JSP-related performance problems in the past, so I was looking through the other options. I'm hoping that somewhere somebody's taken a census of the various options (maybe it'll have to be me) and pronounced which ones are quick, or at least which options there are. Here are the choices I've thought of, ordered from obvious to bizarre:

  • JSP, JSTL
  • Velocity
  • FreeMarker
  • GSP (Groovy JSP)
  • ERB powered by IronRuby or some such craziness
  • Tea

Any suggestions, personal preferences, or other good options for the list?

Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145

6 Answers6

7

StringTemplate - fast, simple and helps enforce MVC separation of concerns. Last I checked, Spring Web MVC doesn't provide a View class for it, but I was able to easily create a custom one.

Community
  • 1
  • 1
Jeff
  • 21,744
  • 6
  • 51
  • 55
  • Have a look at these http://code.google.com/p/stringtemplate-web-extensions/, http://code.google.com/p/springmvc-stringtemplateview/ – Jack Leow Jan 06 '11 at 04:58
5

While I would probably go with FreeMarker or Velocity myself, I am surprised at what you call

JSP-related performance problems

Of all these possible solutions, JSP is obviously the best-performing. After all, JSP pages are compiled to Servlet classes and executed from byte code whereas all the other technologies you mentioned are interpreted.

If you have performance problems, either optimize your JSP code or use a JSP compiler like JSPC to pre-compile your JSP pages (perhaps with maven, using the JSPC-maven-plugin).

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • +1. Btw, other templates are most often cached, so not a huge performance difference. – Bozho Jan 05 '11 at 08:56
  • You're right, of course. JSP should be pretty fast. Our last project, though, grew quite complex, and we had JSP files including JSP files including JSP files. I suspect if we had spent more time optimizing those, we could have really sped things up. – Brandon Yarbrough Jan 06 '11 at 00:41
  • "all the other technologies you mentioned are interpreted": GSP are compiled to Groovy then Java, the way that they work is similar to JSP – Kedare Jan 08 '11 at 00:06
  • @Kedare true, but due to the dynamic nature of Groovy, method resolution happens at runtime, as opposed to Java's compile-time resolution. So while Groovy is not interpreted, it is always slower than comparable Java code. This difference will be significantly smaller in Java 7. – Sean Patrick Floyd Jan 08 '11 at 18:38
3

I prefer Velocity these days. The performance is fine. I like the natural way it decouples the template and the data.

duffymo
  • 305,152
  • 44
  • 369
  • 561
2

I used to use Velocity. The project stagnated a bit and had some known issues, so switched over to Freemarker. I believe (don't quote me) Freemarker came about because Velocity lost momentum. No pun intended.

Since then Velocity has become active again, at least for a while. I prefer Freemarker right now, but either of these two work well. I'd go with whichever one plugs in easier to Spring MVC.

rfeak
  • 8,124
  • 29
  • 28
0

I agree with Sean Patrick Floyd that JSP should be realy fast. In most cases even faster then the other Template engines, even if they are cached.

If you realy run in an JSP related performance issue than I belive you should rethink the way how you use JSP.

And at least, if you have a hot spot which causes the performance issue, than you can build this (hopeflully) small pice by hand (StringBuilder).

So to wrapp this up: I belive JSP is the fasted one (except doing it by hand), but on the other hand, you must have a very special use case to run in a perfomace issue with any of the major template engienes you mentioned.

Community
  • 1
  • 1
Ralph
  • 118,862
  • 56
  • 287
  • 383
0

You should try MVEL. It is faster than anything i know (incl. StringTemplate), really powerful and feels like scripting in plain java.

<p>
   @foreach{index : alphabetical}
     <a href="@{index.uri}">@{index.description}</a>
   @end{}
</p>

or

<a href="@{ua.pageURI}">
   @{org.apache.commons.lang.StringEscapeUtils.escapeHtml(ua.name)}
</a>
Roman K
  • 3,309
  • 1
  • 33
  • 49