Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.1, 2.1.1
-
None
-
None
-
Patch
Description
Hi,
I recently profiled a Struts2 application I'm working on. XWork's TextUtil.translateVariables used up about 30% of the complete time. That's quite a lot!
So I did benchmarked that method and patched it a little.
I was able to cut down the time from 38.9s to 26.6s on my system, using a simple benchmark which executed the tests in TextUtilTest in a loop. That's about 31.7%.
The + operator for String creates an implicit StringBuilder object each time. That method used that quite a lot (in the inner while() loop).
I just made sure that the String concatenations are not in the inner loop.
I also replaced simple String concatenations with String.concat.
This just creates a new String instead of a StringBuilder and then StringBuilder.toString, which then creates a new string.
I think further optimization is possible, but not as easy as this path.
Would be cool if you could include it in the next version.