Mastering C# and Unity3D

JSON Libraries Comparison Followup

I wrote an article when Unity 5.3 came out to test its built-in JSON serializer library against some of the open source JSON libraries. Today’s article updates with Unity 5.4 and adds a requested JSON library—Full Serializer—to the mix. Has Unity 5.4 improved performance? Is the new version of JSON.NET any faster? Can Full Serializer best them all? Read on to find out!

If you want to try out the test yourself, simply paste the above code into a TestScript.cs file in your Unity project’s Assets directory and attach it to the main camera game object in a new, empty project. Then build in non-development mode for 64-bit processors and run it windowed at 640×480 with fastest graphics. I ran it that way on this machine:

Serialization performance varied wildly though. Unity’s JsonUtility was fastest with LitJSON and Json.NET not far behind. Full Serializer, on the other hand, was 3.5x slower than the next-slowest Json.NET.

Deserialization performance was much the same. Unity’s JsonUtility was the quickest with Json.NET then LitJSON roughly 2x slower. Full Serializer was about 3.3x slower than the next-slowest LitJSON.

That said, it’s important to take these performance benchmarks with a grain of salt. Your JSON documents probably don’t look exactly like SaveGame, so you’ll end up with different performance numbers in the “real world” than in this article. For more varied documents put to the test, check out this expansive article. It’s likely that Full Serializer will always be the slowest of the bunch, so you should probably steer clear if you need high performance JSON serialization and deserialization.