Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast and compact object serialization in .NET

I want to use object serialization to communicate over the network between a Mono server and Silverlight clients. It is pretty important that serialization is space efficient and pretty fast, as the server is going to host multiple real time games.

What technique should I use? The BinaryFormatter adds a lot of overhead to serialized classes (Version, culture, class name, property names, etc.) that is not required within this application.

What can I do to make this more space efficient?

like image 479
Dennis Kempin Avatar asked Feb 14 '09 13:02

Dennis Kempin


People also ask

What are the types of serialization available in net?

There are three types of serialization in . Net : Binary Serialization, SOAP Serialization and XML Serialization. Binary serialization is the process where you convert your . NET objects into byte stream.

Which type of Serialisation can be used for faster conversion?

c# - Fastest way to serialize and deserialize .

How many types of serialization are there in C#?

Basic and custom serialization Binary and XML serialization can be performed in two ways, basic and custom. Basic serialization uses . NET to automatically serialize the object.

What is serializing and Deserializing?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. The byte stream created is platform independent.


2 Answers

You can use Protocol Buffers. I'm changing all my serialization code from BinaryFormatter with compression to Protocol Buffers and obtaining very good results. It's more efficient in both time and space.

There are two .NET implementations by Jon Skeet and Marc Gravell.

Update: Official .NET implementation can be found here.

like image 51
Jorge Villuendas Zapatero Avatar answered Sep 19 '22 11:09

Jorge Villuendas Zapatero


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

Northwind .NET serialization benchmarks

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

I also maintain some open-source high-performance .NET text serializers as well:

  • JSV TypeSerializer a compact, clean, JSON+CSV-like format that's 3.1x quicker than the DataContractSerializer
  • as well as a JsonSerializer that's 2.6x quicker.
like image 38
mythz Avatar answered Sep 16 '22 11:09

mythz