tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mfncoo...@gmail.com>
Subject Re: Optimizing tag-lib performance
Date Sun, 24 Jul 2005 03:28:56 GMT
On 7/23/05, Luca Passani <passani@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


Mime
View raw message