During working on sockets and serializing objects over them, I noticed that there are some 3rd party libraries for faster object serialization on Java such as Kryo and FST. Up to now, I expected that Java's serialization is optimized and the fastest. Because, it is language dependent and gives a low level solution that is expected to be faster. However, the considered libraries claim that they are faster than Java.
Can someone explain why Java could not provide the fastest serialization solution? For the sake of what does it give up a better performance?
Thanks in advance.
The main problem with Java Serialization is performance and efficiency. Java serialization is much slower than using in memory stores and tends to significantly expand the size of the object. Java Serialization also creates a lot of garbage.
But the constructor of the class remains uncalled. This results in a variation of Java Standard Flow. This process is inefficient when it comes to memory utilization. Serialization is not useful in applications that need concurrent access without using third party APIs.
Serialization is brittle, it pokes into private field, violates constructor invariance, it's horrible in so many ways. The only thing appealing about it is that it's easy to use in simple use cases. That's what motivated getting it in there. But now, we do have to get it out."
Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
There are several reasons (i am the author of http://code.google.com/p/fast-serialization/)
Reasons:
In order to give better performance, they would have to give up support of old versioning schemes (e.g. the way read/writeObject currently works is suboptimal), and make some things such as versioning support optional or choose more performance sensitive approaches to that (would be possible). Additionally HotSpot might add some intrinsics to improve low level handling of primitives. One needs to have performance in mind when designing an API, which was probably not the case with JDK Serialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With