> James, what an excellent email!
Thanks ;-)
> You've run into a real problem: in the worst case, you're going to have a
> problem indeed. Luckily, though, there are many cases where the worst case
> simply doesn't happen.
Yes I've hit the worst case. It doesn't mean I can't get my job done, its
just that its *so* much slower than it should be. And there is no
workaround, the Java code that is generated by the JSP is so much slower
than it should be. Unfortunately there is no way around it (AFAIK) until the
JSP spec is improved to add more complex flow control to JSP pages.
Right now today JSP tags flow control are just way too simplistic. If you
want to do something as complex as a switch statement efficiently, you
shouldn't use JSP custom tags, you should use Java code. This is a big shame
IMHO
> For example, you mention object creation for the tags; if the same tag is
> used over and over again in a given page, many JSP containers will simply
> reuse previous instances.
I kinda assumed that one too. Though I've tried a few common JSP and when
tags are *nested* then reuse often doesn't happen.
> What's more, object creation isn't nearly as
> expensive with HotSpot in JRE 1.3 as it was in previous incarnations of
> Java.
Sure. Though creating many unnecessary objects and calling many unnecessary
functions per request is a waste of computing resources no matter how clever
HotSpot is getting.
> You can, in fact, include methods in JSP snippets,
Yes you can declare regular all-Java methods - you can't use regular JSP in
the funciton body. So I can't do things like this...
<%! public void foo()
%>
<sometag>
Hello my name is <%= pageContext.getAttribute( "name" ) %>
</sometag>
<%! }
%>
Which is a big shame.
> but tags don't have
> access (normally) to that, and while I believe you could shoehorn
something
> like that together, the purist in my rebels (and gags) at the thought of
how
> tightly coupled your JSP and your JSP tags would be. Since JSP tags are a
> mechanism for loose coupling, it seems to be an intentional mutation of
> purposes.
I agree that there isn't a way to shoehorn anything like this into JSP
today. Though if the JSP spec were enhanced we could easily implement this
kind of funcitonality. I'll mail a more complete proposal shortly...
> <paste>
> >* <foo:loop> creates a new BodyContext object (ok the new IterationTag
can
> >avoid this)
>
> This is pretty inexpensive, really.
Not if done inside a large loop. Creating and manipulating (say) 10,000
objects per request unnecessarily when *there is no need to do this
whatsoever* is a waste of memory and CPU on a heavily loaded web server. I
want to use valuable memory and CPU for doing useful things, not wasting
time doing irrelevant things just because flow control with JSP tags are too
simplistic right now.
> >* all the whitespace inside the <foo:loop> gets written to the output
> >(doesn't it?)
>
> Between each tag, yes. There are ways around this (limit whitespace, use
> XML/XSL to trim, etc.) but the basic problem is still there.
>
> >* creates a new Java object for *each* case tag in *each* loop iteration
> >* initialise each case tag object, calling setParent, setPageContext and
> >other properties etc.
>
> Initialization is a problem, if it's very expensive, yes. (Hint: use
simple
> initialization...)
It still results in many totally unnecessary method calls, whatever way you
look at it. i.e. doing completely irrelevant and totally unnecessary
processing just because custom tags only support very simplistic flow
control.
> >* call the necessary doStartTag() / doEndTag() methods of each tag
>
> See the previous note.
>
> I think your concerns are valid ones, but within the context of JSP
there's
> not really a great solution without breaking constraints JSP puts into
> place.
I agree right now today there's nothing we can do to address this
performance problem. Though by enhancing the JSP specification, we might.
<James/>
James Strachan
=============
email: [EMAIL PROTECTED]
web: http://www.metastuff.com
__________________________________________________________________
If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited.
Views expressed are those of the author and do not necessarily
represent those of Citria Limited.
__________________________________________________________________
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets