0 votes
in Java by
How to improve Serialization performance in java? Please explain the way to speed up serialized object in java.

1 Answer

0 votes

Java Serialization provides us a really very good useful in our developement. But, it has some disadvantages like : bad performance based on application and business requirements. The serialization depends on number and size of attributes, which want to serialize for an object.

There are following things for speeding up the marshaling and un-marshaling of objects during serialization:

  1. Mark the unwanted or non Serializable attributes as transient.
  2. Save only the state of the object, not the derived attributes. Some times we keep the derived attributes as part of the object however serializing them can be costly. Therefore consider calcualting them during de-serialization process.
  3. Serialize attributes only with NON-default values.

    Examples:- Serializing a int variable with value zero is just going to take extra space however, choosing not to serialize it would save you a lot of performance. This approach can avoid some types of attributes taking unwanted space. We will prefer to use Externalizable interface since attribute serialization is determined at runtime based on the value of each attribute.
  4. To use Externalizable interface and implement the readExternal and writeExternal methods to dynamically identify the attributes to be serialized. We can write our custom logic used for serialization for various attributes.

Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.