Bug 53867 - Performance tuning solution for PageContextImpl.XmlEscape
Summary: Performance tuning solution for PageContextImpl.XmlEscape
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Jasper (show other bugs)
Version: trunk
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-13 13:33 UTC by Sheldon Shao
Modified: 2012-10-28 21:59 UTC (History)
1 user (show)



Attachments
Patch for PageContextImpl.java (2.27 KB, patch)
2012-09-13 13:33 UTC, Sheldon Shao
Details | Diff
Comparison test case (1.94 KB, text/plain)
2012-09-13 13:41 UTC, Sheldon Shao
Details
Patch for PageContextImpl.java (2.21 KB, patch)
2012-09-13 14:06 UTC, Sheldon Shao
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sheldon Shao 2012-09-13 13:33:48 UTC
Created attachment 29369 [details]
Patch for PageContextImpl.java

XmlEscape is used to do escape special characters for EL result.
 Currently it gets characters from String one by one and check whether the char is special character or not, than put the char into a StringBuilder.

Most cases the string has no such special characters, However, it always creates a new StringBuilder than do such iteration.

It's better to check whether there is any special characters first.
 If there is special character, then do create a StringBuilder and put those characters in front of te special character into the StringBuilder. 
Again, check the string by character one by one similar as the original logic.



Here is the result of comparison testing between the two methods.

Old escape:1610
New escape:1050
Old escape:1566
New escape:873
Old escape:1437
New escape:905
Old escape:1590
New escape:890
Old escape:1452
New escape:889
Old escape:1547
New escape:889
Old escape:1467
New escape:889
Old escape:1575
New escape:930
Old escape:1479
New escape:874
Old escape:1517
New escape:970
Comment 1 Sheldon Shao 2012-09-13 13:41:37 UTC
Created attachment 29370 [details]
Comparison test case
Comment 2 Sheldon Shao 2012-09-13 14:06:21 UTC
Created attachment 29376 [details]
Patch for PageContextImpl.java
Comment 3 Jarek Gawor 2012-09-18 19:55:02 UTC
Can somebody please take a look at this patch? It's a nice & clean optimization.
Comment 4 Mark Thomas 2012-10-28 21:59:43 UTC
This has been fixed in trunk and 7.0.x and will be included in 7.0.33 onwards.