For my current project, we have a few fairly sizable object graphs that need to be transported from the middleware server to the rich clients. BinaryFormatter has been the serializer of choice because our payload is not shared with other applications, therefore there is no interoperability needs. But because of the large amount of data, we decided to write a test with Google Protocol Buffers to see how much more efficient it would be to use that as an alternative.
We picked protobuf-net over protobuf# because the former is more aligned with other .NET serialization technologies and requires less effort to migrate. And just for comparison, we also decided to add DataContract and Json.NET serializers into the mix.
The test data consists of roughly 5000 objects in the graph. Each test is repeated 100 times and the results are averaged. The serialization pass uses Stream.Null as the destination buffer. The deserialization pass uses a MemoryStream as the source. A warmup pass is performed to force the JIT compilation, and GC.Collect is called before each test begins.
As expected, both Xml and Json serialization result in larger payloads. Protocol Buffers shows a significant (nearly 60%) saving over BinaryFormatter.
Speed test is where protobuf-net implementation truly shined. It is 5x faster than BinaryFormatter for both serializing and deserializing the object graph. Needless to say, we are probably looking to migrate in the near future.



0 comments:
Post a Comment