JSON/BSON (de)serialization performance
David | January 26, 2015If you’re looking for faster JSON/BSON performance, then I recommend taking a look at the Simple Speed Tester framework on GitHub
I have been using the Json.Net and ServiceStack converters in my projects for a while now, but noticed there are even faster options available. Most notably, Google’s Protobuf-Net and NetJson both looked like something I’d like to try. So last week I downloaded Simple Speed Tester and gave it a try.
One thing I noticed was that the NetJSON DLL needed to be updated from v1.0.4.1, so I grabbed the latest from NuGet, which was v1.0.6.2. I wrote a couple of small prototypes and noticed that Protobuf-Net requires you to decorate your data classes with attributes such as below:
[ProtoContract] class DefaultRepresentations { [ProtoMember(1)] int Int; [ProtoMember(2)] uint Uint; [ProtoMember(3)] byte Byte; }
That’s great for minimizing payload, plus maximizing encoding and decoding speed, but not acceptable in a lot of my smaller applications where the classes are ORM code generated POCO’s. Although it’s slightly slower, a quick prototype with the NetJSON DLL showed that no special attribute decorations are required. And it’s nearly as fast.
Here are some tips for using the Simple Speed Tester:
- Open the Solution and update the JsonSerializersBenchmark references to the latest from Nuget
- Open JsonSerializersSpeedTest.cs and change the NetJson v1.0.6.2 (or whichever is the current version)
- Build the Solution
- Open the RunBenchmarks.fsx file and update the #I assembly search paths at the top
- To execute the test, open the RunBenchmarks.fsx, select all in the window, right click and select “Execute In Interactive” to run the script
Here are the results from one of my tests:
I need to see if NetJSON improves the performance of some of my current apps under real world conditions, but I have to say THANK YOU to Yan Cui for making this wonderful tool available on GitHub. Nicely done!