• Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance of custom tag  RSS feed

Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I have written a number of JSP pages that include other JSP pages. At first I used the jsp:include mechanism to do this. However, when testing the performance of this, in some cases, it was unacceptable. Here's why...
Take for example a JSP that generates a list as an HTML table where each item appears in a table row. In the JSP, it iterators over a collection and for each item prints out a value. Between each value, it prints out a line. This line is generated by another JSP.
I learned that the behavior of the jsp:include tag includes the referenced JSP at runtime. Therefore, when this list gets long, the time it takes to generate it increases substantially. If my list contains 100 items, 2 seconds are spent including the lines between the items. If my list contains 500 items, 10 seconds are spent. I also learned that the behavior of the @ include tag includes the referenced JSP at compile time. Therefore, there is a performance hit when the JSP compiles but there is relatively no performance hit at runtime. Even when my list contained 500 items, it didn't appear to run any slower than if my list contained 100 items or 5 items.
Now to my dilemna...
I created a few custom tags for more complicated logic but the essence is still the same. Internally, there is a loop and within the loop, I'm calling pageContext.include(some JSP). I've learned that this is the equivalent of the jsp:include tag and as such, realizing a significant performance hit whenever the loop is executed a number of times.
My question is this...is there a way to improve the performance of my custom tag? Can I simulate the @ include tag in the custom tag? Looking at compiled versions of my JSPs, I learned that for the @ include tag it really is just including the JSP contents just as if I duplicated the code in the custom tag myself. I do not want to do this because I want to avoid having the same code in multiple places for maintenance reasons. Is there a way to call pageContent.include() once (or some other method), save the returned result (say in a string) and simply print it out each time in the loop? Right now I know of only two options...(1) duplicate the code and just put it in the tag or (2) eliminate the custom tag and put the code directly in a JSP where I can use the @ include tag.
Much appreciation for any assistance!
- Kelly
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!