On Thu, 26 Sep 2002, Lister, Tom (ANTS) wrote:
> Date: Thu, 26 Sep 2002 13:21:45 +0100
> From: "Lister, Tom (ANTS)" <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: 'Struts Users Mailing List' <[EMAIL PROTECTED]>
> Subject: RE: Struts and high performance sites revisited
>
> Hi
> I've recently been struggling with performance issues related to tags,
> especially where there are large number in some of our pages. The biggest
> improvment we got was by switching application servers. Specifically by
> upgrading to the latest Tomcat 4.1.11. The difference in response is
> incredible.
> So it would seem that the major issue is with the type of code generated by
> the servlet engine.
> We spent some time looking at the generated code, the major issue being that
> every tag reference is created as a new object. There must be better way to
> do this. Until this point I was wrongly assuming that the tags were run as
> just method calls on one instance.
The JSP Specification provides many standard opportunities that a JSP page
compiler can use to improve the quality of the generated code for a custom
tag invocation. One of the simplest is to reuse tag instances (as the
Jasper 2 compiler in Tomcat 4.1 can do), but there are more aggressive
things you can do as well. Consider something like this:
<c:forEach ... something that loops 100 times ...>
<foo:bar name="x" value="y"/>
</c:forEach>
Not only is it legal to reuse the custom tag instance for the "bar" tag
(instead of creating 100 instances the way Tomcat 4.0 does), but the page
compiler need not even call the setName() and setValue() methods 100 times
inside the loop -- these can be moved outside the loop using standard
techniques that optimizing compilers have used for decades.
The JSP page compiler in Tomcat 4.1 and 5.0 (called "Jasper 2") was
rewritten from the ground up, primarily in order to make optimizations
like this possible. You are seeing the fruits of this effort in 4.1, but
we are by no means done with improving the optimizations that the page
compiler can perform.
> will JSTL improve on this ?
>
JSTL by itself doesn't change the code that is generated for a custom tag
-- that's up to the page compiler. But the page compiler does have the
opportunity to recognize JSTL tags (since they are a standard now) and
generate specially optimized code (for example, turning a <c:forEach> into
a real Java "for" statement instead of a custom tag invocation), as long
as the semantic requirements are met. So, once the page compilers have
been improved in this manner, using <c:forEach> will definitely run faster
than a Struts <logic:iterate> tag that iterates the same number of times
(unless someone were to optimize their page compiler for Struts tags,
which seems less likely than optimizing for JSTL :-).
> :-)
> Tom Lister
> * 020 7612 3030
> * [EMAIL PROTECTED]
>
Craig McClanahan
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>