I'm working on a product that is heavily based on a JSP tag library
which lets developers write their pages using JSP tags only. The
result is JSP pages that make heavy use of nested JSP tags, some of
which implement iteration.

One of the most complex pages we have takes about 6 seconds to run in
Tomcat 3.2, while in Resin it runs in 0.06 seconds. We believe the
cause of this to be the way Tomcat (that is, Jasper) generates the
JSP servlet Java code.

Every time a tag is executed the following actions are performed:

 1. a new tag instance is instantiated
 2. the new instance is configured (set*() methods called)
 3. the tag is executed

Jasper now has a setting that allows us to not repeat step #1 every
time a tag is executed, which brought page execution down to 3 seconds
(from the original 6), but this still isn't good enough for our
purposes.

In my opinion, it is also necessary to be able to not repeat step #2
every time a tag is executed. If we can avoid this we save an awful
lot of method calls, and our tag implementations can also perform a
number of costly operations at creation-time, which they then won't
have to repeat every time they are executed. I expect that with this
change our execution times will be more reasonable.

As far as I can tell, the only way to get rid of step #2 is to modify
Jasper. I've looked at the source code, and I think I see a way to do
this with the sources on the MAIN branch. (BTW, is that the latest and
greatest version of Jasper?) The current approach with a tree of
generators makes this difficult, and the resulting Java code will be
ugly, but it can be done. When Jasper is rewritten to use visitors
this can be done much prettier.

Basically, my idea is to generate code like this for each tag:

  ClassName variable = taghash.get("variable"); // [1]
  if (variable == null) {
    variable = new ClassName();
    taghash.put("variable", variable);
    // do the setters here
  }
  // execute tag in the usual way

Before I start I would like to know:

  - is anyone else working on this already? is there some way to
    achieve this already?

  - which version of the Jasper sources should I be working on?
    the MAIN branch?

  - what do people think of my proposed solution? I know it is not
    very nice, but as long as the code has to be generated from within
    the current generators, which are called the way they are, I don't
    see any better alternative.

  - if I do make this change, what are the chances that it will be
    accepted into the Jasper sources?

  - if I do make this change, what version of Tomcat could the
    modified Jasper become part of?

--Lars M.

[1] I've noticed that the Jasper sources seem to use 1.1 collections,
    instead of the 1.2 collections. Is that on purpose?

Reply via email to