Fast Serialization
Ok - here's the deal.
Im currently passing objects between two instances of an application. Im currently using standard Serialization to get an "on the wire" format. The reason for going the Serialization route is that new classes are added and changed frequently by a large team of varied experience levels - so an intrusive "each class has to know how to write itself out" mechanism just isn't flexible enough.
Anyway, it turns out that Serialization isn't cutting it performance wise. My objects are about 7k on the wire, Im not serializing objects I shouldn't be, and Im only getting a few hundred serializations per second (note Im talking about the serialization itself here - not sends across the network).
So I got to thinking about how I could speed it up and I'd like to run an idea past you...
What about a custom "fast" serialization mechanism? As classes are loaded, they are instrumented with the code which lets them write themselves out through the stream.
As an example, take the following class:
publicclass SomeDomainType{
privatelong someLong;
privateint someInt;
private String someString;
private SomeOtherType other;
// ...
}
At class load time, this would be added:
publicclass SomeDomainTypeimplements FastSerializable{
// .. members as before
publicvoid serialize(FastSerializeStream out){
super.serialize(out);
out.write(someLong);
out.write(someInt);
out.write(someString);
out.writeObject(other);
}
}
Obviously a "de-serialize" method would be added as-well.
So, each type gets instrumented with a non-reflection based way of (de)serializing.
We'd need to have a way of creating objects without invoking constructors for the deserialization part - but that is possible with a bit of magic.
The other thing to bear in mind is that we do not have the complex class version / class loading issues that normal java (de)serialization has to deal with (we're sending objects between two instances of the same app using the same classes).
So why am I posting this anyway?
Well, I know that serialization has been improved quite a bit in the last few java versions - and I think that some code generation for reflection access already goes on behind the scenes. So it may be that what Im proposing is already some-how catered for in a different way.
This method would certainly get rid of run-time reflective access for serialization though and probably wouldn't be too hard to implement.
Any comments would be appreciated.

