I’m writing my own serializer for NOODB. The benefit of it is that I can make it work exactly the way I want it to. The cons list is much more substantial: I’m reinventing the wheel. I looked at the DataContractSerializer again tonight. It would be great if I could use that. The first thing it doesn’t do, that I need, is include the type name in the elements of the complex types. I need the type name; I can’t infer it from the property type because the property type may be “IMovie”, but the implementation was “Movie”. When I deserialize, how would I know which concrete class to instantiate? How does the DataContractSerializer know (does it support this? Tbd. I will try it).
So, I did some simple PSR of the NOODB serializer vs. The DataContractSerializer.
Good news! My serializer is 153X faster than the DataCOntractSerializer!!! Can you believe it? How awesome am I?
Kidding. The DCS is faster by a hair. If you run the test 10 times, mine might win one or two, but that’s just luck. Typically, DCS wins. With 100,000 serializations, its usually about 1/10th of a second faster. That ratio holds up. With a million serializations, it’s about a second faster. (Incidentally, a million serializations takes 22 seconds.)
I looked into this to find out what’s taking “so long”. The only difference in the output, as already mentioned, is that I’m outputting the type name. I commented that out, and NOODB became faster. It’s consistently 2/10th of a seconds faster than DCS. Do some math, and you’ll see that over 100,000 rows, 3/10ths of a second is lost to creating the type-name attribute. With it, NOODB is slower. Without it, NOODB is faster.
But Seriously, Folks
My so-called “serializer” is nothing more than a recursive loop that parses a type and writes it to an XmlTextWriter. I tried caching some type info to no benefit, so it’s just raw code without any tricks. It does not support collections yet. The DCS is obviously a far more robust and time-tested serializer. I hope that as the serializations become more complex that I can stay in the ballpark. That’ll be good enough for me.
THe NOODB serialzer isn’t as fast as the DCS, but so far at least, it’s fast enough.