16

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CodingHero
  • 173
  • 2
  • 5
  • It looks like there are two questions here... Fastest serialization is one, the other is serialization with lowest mem footprint. – Mauricio Scheffer Mar 09 '09 at 16:04
  • @Mauricio: It's always a matter of balance. You normally search for the optimum between the two qualities, so you consider both at the same time. – Stefan Steinegger Sep 09 '11 at 12:40
  • possible duplicate of [Fastest way to serialize and deserialize .NET object](http://stackoverflow.com/questions/4143421/fastest-way-to-serialize-and-deserialize-net-object) – nawfal Jul 10 '14 at 17:43

4 Answers4

10

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.

LukeH
  • 263,068
  • 57
  • 365
  • 409
  • 7
    Whats the difference between these three .NET implementations? – Stefan Steinegger Sep 09 '11 at 12:37
  • 1
    @StefanSteinegger They're different implementations of protobuf, by different developers. As for the situation now: proto# seems to have vanished, both protobuf-net and protobuf-csharp-port have been implemented by excellent developers. The correct links are https://github.com/mgravell/protobuf-net and https://github.com/jskeet/protobuf-csharp-port . – atlaste Apr 26 '16 at 07:15
5

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.

Bob Bryan
  • 3,687
  • 1
  • 32
  • 45
mythz
  • 141,670
  • 29
  • 246
  • 390
  • What about Simon Hewitt's library? See *[Optimizing Serialization in .NET - part 2](http://www.codeproject.com/dotnet/OptimizingSerialization2.asp)* or *[How to serialize big objects in .NET?](http://stackoverflow.com/questions/709399/how-to-serialize-big-objects-in-net-outofmemory-exceptions/1290530#1290530)*. – Peter Mortensen Sep 09 '11 at 12:37
2

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.)

Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
  • C structs (or C++ in my case) would be great, but .Net (as required by OP) and Java do not serialize just the struct's data, they also serialize the structs definition to a point. Also, protocol buffer allows adding _"new fields to your message formats without breaking backwards-compatibility;"_ [see Developer Guide](https://developers.google.com/protocol-buffers/docs/overview). – Trisped Feb 19 '13 at 00:02
1

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.

Community
  • 1
  • 1
Toxantron
  • 2,218
  • 12
  • 23