Serialization is a generic marshalling and demarshalling algorithm, with many hooks for customization. As an experienced programmer, you should be skeptical—generic algorithms with many hooks for customization tend to be slow. Serialization is not an exception to this rule. It is, at times, both slow and bandwidth-intensive. 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.
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
) is implemented, and what the
superclass structure is. What’s more, using the
default serialization mechanism, (or calling
) from within
writeObject( )) will use reflection to
discover all the field values. This can be quite
serialVersionUID is a simple, and often
surprisingly noticeable, performance improvement.
If you don’t set
serialVersionUID, the serialization
mechanism has to compute it. This involves going
through all the fields and methods and computing a
hash. If you set
serialVersionUID, on the other hand, the serialization mechanism simply looks up ...