Details
-
Type: Improvement
-
Status: Closed
-
Priority: Major
-
Resolution: Duplicate
-
Affects Version/s: 1.2.2, 1.3
-
Fix Version/s: None
-
Component/s: Core
-
Labels:None
-
JDK version and platform:Sun 1.5.0_12 for Windows
Description
The profiling results for our application (which uses XStream 1.2.2 / 1.3) suggest that the keying mechanism used by the field alias mapper leads to a performance hotspot (in terms of execution time) due to the combination of the two factors number of invocations (the key method is called relatively often during serialization), and costs (in terms of execution time) per invocation, caused by the expensive string operations (implicit use of java.lang.StringBuffer init, append, toString in the key method).
I recommend reworking the key mechanism so as to avoid using string operations. Maybe using the parameter object references as a key instead of concatenating their string representations could be a more efficient approach?
The number of calls to the key method could also be reduced in some instances, e.g. method shouldSerializeMember(Class definedIn, String fieldName) could first check whether fieldsToOmit is empty before constructing the key with which to search the hashset.
Issue Links
- is superceded by
-
XSTR-517 Misc performance improvements (for detected HotSpots via profiler)
I noticed the same hot spot, and although it's not the biggest one (access to class/field info takes most of the time under 1.6 JVM), it pays off it to resolve this one too.
To that end, please see attached patch. Creating temporary key object is more efficient than constructing temporary strings.