Serializable vs. Externalizable

I’ve been testing some assumptions we have always held about moving data using EJBs (and RMI) and what I’ve found is not exactly what I expected. In the places I have worked, we held the belief that Serializable, by default, sent too much information over the wire and that it was slow. This seems to be a mixed case.

This test is not exactly a real-world test, I’m creating 10,000 small objects in an ArrayList and writing the list to disk using ObjectOutputStream. When the object implements *Externalizable* it is much larger (about 90Kb for 10,000 objects) than when is implements *Serializable*. However, *Serializable* is about 2 or 3 times slower than *Externalizable* due to reflection costs. I guess the moral is too make sure your bottleneck is really a bottleneck in your app before fixing it. Is Serializable’s reflection cost more than the saving in bandwidth?

Comments are closed.