Seren (SERialization ENhancer) aims to enhance your classes so that they are much quicker to serialize.
It does so by instrumenting the classes at load-time to generate optimized
readObject methods, based on the best known practices (as seen in the JavaSpecialist Master Course).
The source code available on GitHub.
Feel free to take a look at it, any comment appreciated !
How does it work ?
Which classes should be enhanced is determined by a "filter", which is configured in the "
seren.properties" configuration file (see below).
In each selected class, Seren will detect and optimize all non-static, non-transient fields. Also, final fields are not supported, because only the standart serialization system is allowed to re-set the value of final fields ; if you wish to serialize a class with final fields, please hide it from Seren.
How much faster will my objects be serialized ?
It entierely depends on the types of their fields. Numeric wrappers (
Strings are much faster (up to 3 times faster according to my – not necessarily accurate – benchmarks). Primitives are only as fast as usual.
Is there any risk / downside ?
There is absolutely no risk in testing Seren. As a Java Agent, it instruments your classes at load-time, and it totally transparent to your application. No need to modify any existing code either. Try it and measure the speed gain ; if it does not convince you, just remove the Java Agent option from the command line and you're done.
As for downsides, Seren provides a boost in serialization speed, but may generate slightly bigger serialized streams, so you sould not use it if you send big amounts of serialized data over a slow network. On the other hand, Seren works wonders for in-memory serialization (ex: EHCache make deep copies of your objects by serializing them to an in-memory byte array).