You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Luca Passani <pa...@eunet.no> on 2005/07/23 17:18:57 UTC
Optimizing tag-lib performance
Hello again,
I would like to improve the performance of a tag-lib I have created.
Some obvious optimizations would be to turn things like:
---------------
out.print(" href=\""+href+"\"");
//title is optional
if (!title.equals("")) {
out.print(" title=\""+title+"\"");
}
---------------
into (is this what they call "string internalization"?):
---------------
final static String HREF_ATT = " href=\"";
final static String TITLE_ATT = " title=\"";
:
StringBuffer sb = new StringBuffer();
:
sb.append(HREF_ATT);
:
out.print(sb.toString());
---------------
Before I start applying these changes, though, I would like to be able
to sort of measure the improvements.
I tried something as basic as:
<%
long startTime = System.currentTimeMillis();
%><%@ taglib uri="/WEB-INF/tld/wall.tld" prefix="wall"
%><wall:document><wall:xmlpidtd />
:
<wall:body>
<wall:menu colorize="true" autonumber="true">
<wall:a href="http://url1" title="Games">Games</wall:a>
<wall:a href="http://url2" title="Horos">Horoscopes</wall:a>
<wall:a href="http://url1" title="Kids">Kids</wall:a>
<wall:a href="http://url2"
title="Movies"><wall:b>Movies</wall:b></wall:a>
<wall:a href="http://url1" title="Music">Music</wall:a>
<wall:a href="http://url2" title="Radio">Radio</wall:a>
<wall:a href="http://url2" title="TV">TV</wall:a>
</wall:menu>
</wall:body>
</wall:document>
<%
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
System.out.println(elapsedTime);
%>
the problem is that when I reload the page, the number of milliseconds
is zero and occasionally 8,9 or 10
(I see output in the tomcat console running on my laptop, so I am sure
that the browser is not caching).
Questions:
- is there something I am getting basically wrong?
- is my tag-lib optimized enough that I don't need to care about further
optimization? possibly
because the compiler/JVM already did the optimization for me?
- are there better ways/tools to measure tag-lib performance?
Thanks
Luca
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Optimizing tag-lib performance
Posted by Martin Cooper <mf...@gmail.com>.
On 7/23/05, Luca Passani <pa...@eunet.no> wrote:
> Hello again,
>
> I would like to improve the performance of a tag-lib I have created.
What I would recommend is extracting the "work" of your tags into
methods that do not depend on the container being around. Then you can
write simple JUnit tests for that code, and profile it without the
container.
For example, in your refactored code below, pull all of the code that
builds up the string buffer into a separate method, and then only do
the out.print() from the JSP API method.
--
Martin Cooper
> Some obvious optimizations would be to turn things like:
> ---------------
> out.print(" href=\""+href+"\"");
> //title is optional
> if (!title.equals("")) {
> out.print(" title=\""+title+"\"");
> }
> ---------------
> into (is this what they call "string internalization"?):
> ---------------
> final static String HREF_ATT = " href=\"";
> final static String TITLE_ATT = " title=\"";
> :
> StringBuffer sb = new StringBuffer();
> :
> sb.append(HREF_ATT);
> :
> out.print(sb.toString());
> ---------------
>
> Before I start applying these changes, though, I would like to be able
> to sort of measure the improvements.
> I tried something as basic as:
>
> <%
> long startTime = System.currentTimeMillis();
>
> %><%@ taglib uri="/WEB-INF/tld/wall.tld" prefix="wall"
> %><wall:document><wall:xmlpidtd />
> :
> <wall:body>
> <wall:menu colorize="true" autonumber="true">
> <wall:a href="http://url1" title="Games">Games</wall:a>
> <wall:a href="http://url2" title="Horos">Horoscopes</wall:a>
> <wall:a href="http://url1" title="Kids">Kids</wall:a>
> <wall:a href="http://url2"
> title="Movies"><wall:b>Movies</wall:b></wall:a>
> <wall:a href="http://url1" title="Music">Music</wall:a>
> <wall:a href="http://url2" title="Radio">Radio</wall:a>
> <wall:a href="http://url2" title="TV">TV</wall:a>
> </wall:menu>
> </wall:body>
> </wall:document>
> <%
> long stopTime = System.currentTimeMillis();
> long elapsedTime = stopTime - startTime;
> System.out.println(elapsedTime);
> %>
>
> the problem is that when I reload the page, the number of milliseconds
> is zero and occasionally 8,9 or 10
> (I see output in the tomcat console running on my laptop, so I am sure
> that the browser is not caching).
>
> Questions:
>
> - is there something I am getting basically wrong?
> - is my tag-lib optimized enough that I don't need to care about further
> optimization? possibly
> because the compiler/JVM already did the optimization for me?
> - are there better ways/tools to measure tag-lib performance?
>
> Thanks
>
> Luca
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Optimizing tag-lib performance
Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Luca Passani <pa...@eunet.no> wrote on 07/23/2005 11:18:57 AM:
<snip/>
> the problem is that when I reload the page, the number of milliseconds
> is zero and occasionally 8,9 or 10
> (I see output in the tomcat console running on my laptop, so I am sure
> that the browser is not caching).
>
> Questions:
>
> - is there something I am getting basically wrong?
<snap/>
JSP performance is container specific. This may or may not be important
for your testing purposes. Given that the tag impls are in Java, you could
test there.
> - is my tag-lib optimized enough that I don't need to care about further
> optimization? possibly because the compiler/JVM already did the
> optimization for me?
<snip/>
There are two compilers in tow, the JSP compiler and the Java compiler,
followed by the target JVM. Depending on what combinations get picked
(users often do not have a choice for various unrelated reasons), the
compiler based optimization mileage may vary. Since you've thought about
the obvious bits, I would concentrate on getting more visibility to the
sources, rather than hacking away at optimizations alone.
> - are there better ways/tools to measure tag-lib performance?
<snap/>
For the Java bits, I'm sure you can find a bunch. For tag files, I don't
have a good container agnostic answer myself.
-Rahul