Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest serializer and deserializer with lowest memory footprint in C#?

I am currently using the binary formatter (Remoting) to serialize and deserialize objects for sending around my LAN.

I have recently upgraded from 2.0 to .NET 3.5. Has 3.5 introduced any new types to improve serialization performance?

I’ve looked at the DataContractSerializer, but this serializes anything to underlying XML right … which must increase the memory footprint.

What’s the fastest serializer for sending objects across my LAN? I don’t care a about interop or versioning …. I need speed!

I am open to third-party open source alternatives.

like image 696
CodingHero Avatar asked Mar 09 '09 15:03

CodingHero


4 Answers

It sounds like Protocol Buffers might be what you're looking for.

There are three .NET implementations that I'm aware of: protobuf-net, protobuf-csharp-port and Proto#.

The performance comparisons show that Protocol Buffers outperform the built-in serializers in terms of both size and serialization/deserialization speed.

like image 194
LukeH Avatar answered Oct 05 '22 23:10

LukeH


In the performance comparison linked by @Luke, notice that DataContractJsonSerializer performs very well compared to the other MS serializers.

Given the ubiquity of JSON, and the ease of which you can use DataContractJsonSerializer, I don't see much reason to use "protocol buffers". JSON will be easier to debug when bouncing between languages and platforms, and it will compress beautifully.

(I love how Google takes CS 101 concepts and becomes famous for implementing them. In C, we call "protocol buffer" "struct"s. They work great.)

like image 43
Frank Krueger Avatar answered Oct 05 '22 23:10

Frank Krueger


I have some benchmarks for the leading .NET serializers available based on the Northwind dataset.

@marcgravell binary protobuf-net is the fastest implementations benchmarked that is about 7x faster than Microsoft fastest serializer available (the XML DataContractSerializer) in the BCL.

Microsoft's JsonDataContractSerializer is pretty slow - over 9x slower that protobuf-net and over 3.6x slower than my own JsonSerializer.

like image 33
mythz Avatar answered Oct 05 '22 22:10

mythz


As I demonstrated in this answer the generated code might be the fastest serializer. However it is in an early stage and still lacks a couple of features that other serializers offer.

like image 40
Toxantron Avatar answered Oct 06 '22 00:10

Toxantron