Few days ago I have stumble on a problem reported by a customer saying that communication between client and a server application is slow. So I have take a look what may be causing the problem and found that serialization process is slow, well not that slow as it was creating large amount of data which was sent over the wire. At the end I had to optimize whole process, to do that I had to find .Net serializer that is producing less data. This is a small overview of the available .Net serialization libraries.
Here is a list of serialization libraries that I have tested
(.NET Built-in serializer) - this is the serializer we are using at the moment and let's say it is producing around 100kb of data (just for comparison).
(.NET Built-in serializer) - Our test has shown that this is a powerful serializer, which will generate a 50% less data then the binary serializer, we didn't test the serialization speed but we have included some speed test links below, and they say this is pretty fast serializer. The downside for this serializer is that you need to know the object type which you want to serialize and deserialize (and the whole object graph to serialize the sub-objects).
(.NET Built-in serializer) - If you only trust the .NET serializers then this should be your choice, it will produce almost the same amount of data as the DataContractSerializer (50% less then BinaryFormatter) with the almost the same speed but you don't need to know the object type (object graph). Use it with the BinaryWriter
and you should get some great results.
(.NET Built-in serializer) - JSON version of the DataContractSerializer which is super fast and has a small data footprint but it requires you to know the object graph.
(.NET Built-in serializer) - One of the oldest built-in serializers available it is slow and has a big data footprint. You can read more about it here:
- Fast and compact serializer which can be used in a same manner as BinaryFormatter. Author claims it is 50 times faster, we didn't get that great results but it was much faster then BinaryFormatter and it was producing 20%-30% less data. A good alternative to BinaryFormatter, you can find out more about the OpenNxSerialization here
- The fastest and most compact text-based serializer for .NET. A great library if you are looking for alternative for XmlSerializer or DataContractSerializer. Although we didn't get it working in our real-world project, it is very simple to use so we advise you to consider it as serious alternative. You can read more about it here.
- "a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more.
) The fastest serializer with the smallest footprint that we have tested. It is Google Protocol Buffers
based serializer ported to .NET. It is super fast binary formatter and the data footprint is super small (Compared to BinaryFormatter), it is built upon the Google Protocl Buffer encoding
standard that's why it is producing small amount of data. Downside is that he requires you to know the object graph but considering the benefits from this serializer I'll suggest you find a way around that problem. Although it is under heavy development by Mark Gravel
(ProtoBuf-net v2) it is an easy to use serializer, and we need to mention that he was more than willing to help us get the v2 up and running.
These are all great serializers but every serializer has it's own purpose and at the end we have chosen the ProtoBuf-net v2 as our serializer, now we are working on the ProtoBuf-net implementation in our real-world project so we will see how it goes.
I hope this will save you some time while searching for a serialization solution.
Here are some of the helpful links I have found while trying to find the solution for our problem.
Comparing the Performance of .NET Serializers
A small serialization speed overview (ServiceStack performed wide range of speed test that can be found here
||Larger than best
||Avg per iteration
||Slower than best
Good utility (technique) to help you detect the unknown types when using XMLSerializer and alike.
Serializable Extra Types for .NET 4