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

4

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.

Beedon answered 9/3, 2009 at 15:42 Comment(3)
It looks like there are two questions here... Fastest serialization is one, the other is serialization with lowest mem footprint.Totter
@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.Eatable
possible duplicate of Fastest way to serialize and deserialize .NET objectRhythmist
R
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.

Regale answered 9/3, 2009 at 16:8 Comment(2)
Whats the difference between these three .NET implementations?Eatable
@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 github.com/mgravell/protobuf-net and github.com/jskeet/protobuf-csharp-port .Ole
A
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.

Addington answered 25/8, 2010 at 17:44 Comment(1)
What about Simon Hewitt's library? See Optimizing Serialization in .NET - part 2 or How to serialize big objects in .NET?.Obloquy
B
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.)

Bother answered 11/3, 2009 at 1:45 Comment(1)
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.Exterritorial
B
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.

Bowing answered 26/4, 2016 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.