I am attempting to improve our current serialization performance by switching from the Serializable interface to Externalizable, but have not found a lot of documentation on best practice for creating custom and performant serialzations. My current solution is about twice as fast as the stock Java serialization, which while good, doesn't seem like the vast improvement I was expecting (Benchmark of serialization techniques/libraries)
For anything but primitives I've taken the approach of writing a 0 or 1 to show the field exists, then reading the field if the value is 1:
if (in.read() == 1) {
name = in.readUTF();
}
Does that sound about right? Are there better encodings to use? What about Maps, Lists, and other complex data structures. Is the default serialization for Enums fine?
Thanks.