What do classes optimized by Externalizer4J look like? Want to see Externalizer4J’s optimization in action? Showing the actual optimization by Externalizer4J is a challenge for the following reaons:
- Externalizer4J is very fast: not a very rewarding experience for the viewer ?
- Since it is an optimization tool there is not real visual component to its operation
- Please see the Configuration reference to get more output during the optimization
Meet the class Person
A first small example to illustrate what Externalizer4J does. This example will use a Person class. The picture below shows all there is to know about it. The class has 3 fields, a single toString() method and of course it implements java.io.Serializable.
The Person class represents the full name, birthday and weight of a person. This Serializeable class has not methods except toString().
Optimized class Person
Externalizer4J works at the bytecode level. The source code is never needed. To illustrate the optimization by Externalizer4J we need to decompiled the class. In this case we use JD-GUI to decompile the class to see the corresponding code. The picture below shows the decompiled code for the Person class.
- the class now implements Externalizable
- the class now has new writeExternal() and readExternal() methods
- the existing toString() method remains unchanged
The optimizations details
- the line numbers correspond to the line numbers in the source code
- the new methods have been added at the end of the class.
- the logic inside writeExternal() and readExternal() only uses the standard JDK API
- The estimated gain in serialized size is 68%.
The decompiled Person class after optimization by Externalizer4J. Initially only implemented the Serializable interface. Externalizer4J has converted it into a class that also implements Externalizable. The that end a tailored writeExternal() and readExternal() methods have been were generated.