Is there any significant performance gain in serialization from declaring instance variables as transient?
Created May 4, 2012
Serialization saves only the state of the object. If some instance variables don't contribute to the state, there's no sense in spending the extra time and bytes serializing them. As for how much performance you'll gain, that depends on your objects. If the instance variables are primitives, you won't save much, but if the instance variables are object references, the savings can be much greater.
If however the instance variable you declare transient are part of the state of the object, you will need to reconstruct the transient values upon deserializing. This requires you to implement private void readObject() and private void writeObject(). In general, objects which implement readObject() and writeObject() have better serialization performance because the object streams don't have to use reflection as much to figure out the detailed structure of the object. But this is by no means a hard-and-fast rule - it's easy to decrease performance by an inefficient readObject() or writeObject() method.
Further information about improving performance of serialization can be found at:
http://www.jguru.com/jguru/faq/view.jsp?EID=3419and
http://www.jguru.com/jguru/faq/view.jsp?EID=42504