Tuesday 6 October 2015

Performance Issues while generating serialVersionUID


Serialization is a generic marshalling and demarshalling algorithm, with many hooks for customization

There are three main performance problems with serialization:
It depends on reflection,
It has an incredibly verbose data format, and
It is very easy to send more data than is required.

Serialization Depends on Reflection:

The dependence on reflection is the hardest of these to eliminate. Both serializing and deserializing require the serialization mechanism to discover information about the instance it is serializing.

At a minimum, the serialization algorithm needs to find out things such as the value of serialVersionUID, whether writeObject() is implemented, and what the superclass structure is.

What's more, using the default serialization mechanism, (or calling defaultWriteObject() from within writeObject() will use reflection to discover all the field values. This can be quite slow.

If we don't define serialVersionUID, the serialization mechanism has to compute it. This involves going through all the fields and methods and computing a hash.

If we define serialVersionUID, the serialization mechanism simply looks up a single value.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...