views:

1300

answers:

4

Does anyone have any information on the performance characteristics of Protocol Buffers versus BSON (binary JSON) or versus JSON in general?

  • Wire size
  • Serialization speed
  • Deserialization speed

These seem like good binary protocols for use over HTTP. I'm just wondering which would be better in the long run for a C# environment.

Here's some info that I was reading on BSON and Protocol Buffers.

+2  A: 

protocol buffers is designed for the wire:

  1. very small message size - one aspect is very efficient variable sized integer representation.
  2. Very fast decoding - it is a binary protocol.
  3. protobuf generates super efficient C++ for encoding and decoding the messages -- hint: if you encode all var-integers or static sized items into it it will encode and decode at deterministic speed.
  4. It offers a VERY rich data model -- efficiently encoding very complex data structures.

JSON is just text and it needs to be parsed. hint: enoding a "billion" int into it would take quite a lot of characters: Billion = 12 char's (long scale), in binary it fits in a uint32_t Now what about trying to encode a double ? that would be FAR FAR worse.

Hassan Syed
+10  A: 

Thrift is another Protocol Buffers-like alternative as well.

There are good benchmarks from the Java community on serialization/deserialization and wire size of these technologies: http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking

In general, JSON has slightly larger wire size and slightly worse DeSer, but wins in ubiquity and the ability to interpret it easily without the source IDL. The last point is something that Apache Avro is trying to solve, and it beats both in terms of performance. It has no C# implementation at the moment though.

Michael Greene
nice information (+1)
Hassan Syed
Agreed - good info.
Jeff Meatball Yang
Small message size doesn't automatically translate into fast perforamnce, see this article http://soa.sys-con.com/node/250512
vtd-xml-author
+10  A: 

This post compares serialization speeds and sizes in .NET, including JSON, BSON and XML.

alt text

alt text

http://james.newtonking.com/archive/2010/01/01/net-serialization-performance-comparison.aspx

James Newton-King
Why was this downvoted?? Anyway - your work is informative - thanks James.
Jeff Meatball Yang
+2  A: 

I have some benchmarks on different serializer implementations in .NET based on dataset from the Northwind Database.

Basically protocol buffers (protobuf-net) is around 7x quicker than the fastest Base class library Serializer in .NET (XML DataContractSerializer). Its also smaller than the competition as it is also 2.2x smaller than Microsofts most compact serialization format (JsonDataContractSerializer).

I have a highly-optimized JsonSerializer which is the closest to matching the perf of protobuf-net which is only 2.58x slower than protobuf-net.

mythz

related questions