GameJSON 0.0.2

dotnet add package GameJSON --version 0.0.2
                    
NuGet\Install-Package GameJSON -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GameJSON" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GameJSON" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="GameJSON" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GameJSON --version 0.0.2
                    
#r "nuget: GameJSON, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GameJSON@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GameJSON&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=GameJSON&version=0.0.2
                    
Install as a Cake Tool

Game JSON

A fast no dependency JSON library for C#, particularly aimed at games. This was built to satisfy the need that most JSON libraries cannot be sped up enough to (de)serialize files in a sufficient amount of time without incurring a framerate drop. Currently only deserializes strings and serializes to strings.

Structure

Comes in 2 parts

  • GameJSON.ReflectionParsing - Reflection Library for serializing/deserializing objects to/from JSON. Contains JSON class.
  • GameJSON.ManualParsing - A manual parsing library that ReflectionParsing is built on top of. If ReflectionParsing doesn't (de)serialize your JSON fast enough, using ManualParsing to manually (de)serialize will give you a massive performance boost. Contains JSONReader and JSONWriter class.

Reflection Parsing Goals

  • All fields on an object will be serialized and deserialized
  • Users can opt into serializing properties with SerializeProperty attribute
  • Auto properties are serialized automatically (i.e. public int MyAutoProperty { get; set; })

Manual Parsing Goals

  • Have as few additional allocations as possible
  • Give the user as much power over serializing the JSON as they want to achieve great performance

Performance

These are the performance test results. As a summary, this behaves significantly faster than Newtonsoft in most cases except when loading using reflection with a hot cache. This is most likely because GameJSON does absolutely no caching. Most importantly though, GameJSON manually deserializes JSON at 5ms cold (i.e. first run with data type) and 2ms hot (i.e. second run with data type), whereas Newtonsoft manually deserializes in 95ms cold and 11ms hot. This means that files can be loaded with GameJSON in games without incurring a huge frame spike.

On Android, the differences between GameJSON and Newtonsoft/JSON.Net are vast, with GameJSON being faster in every category.

Tests

I created an object TestPositions with a string and a Vector3, and had each library serialize and deserialize these objects.

  • Windows - i5-9600K with Mono backend
  • Android - Galaxy S10 Lite with IL2CPP backend

1000 Test Positions Cold Platform

This captures the first run of serializing/deserializing 1000 TestPositions on the respective Platform

1000 Test Positions Hot Platform

This captures the second run of serializing/deserializing of 1000 TestPosition on the respective Platform

Results

TestName 1000 TestPositions Cold Windows 1000 TestPositions Hot Windows 1000 TestPositions Cold Android 1000 TestPositions Hot Android
GameJSON Reflection Serialize 14ms 12ms 58ms 24ms
GameJSON Reflection Deserialize 23ms 17ms 106ms 35ms
Newtonsoft Serialize 142ms 11ms 452ms 39ms
Newtonsoft Deserialize 180ms 30ms 577ms 98ms
GameJSON Manual Serialize 7ms 4ms 10ms 9ms
GameJSON Manual Deserialize 5ms 2ms 3ms 2ms
Newtonsoft Manual Serialize 79ms 5ms 19ms 13ms
Newtonsoft Manual Deserialize 95ms 11ms 30ms 21ms
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 525 11/4/2022
0.0.1 487 11/3/2022

Extremely alpha release