Newtonsoft is a pretty fast JSON serializer, but you can make it even faster!
By default, JsonConvert uses reflection to recursively search through the structure of an object during the serialization process. By implementing a custom JsonConverter that already knows the exact structure of the object, you can significantly increase serialization performance.
How much faster? That depends! The more complicated the data structure, the larger the performance gain. Below is a simple example...
| Action | Method | Milliseconds | Performance Increase |
|---|---|---|---|
| Serialize | Standard | 1134 | 115.59% |
| Custom | 526 | ||
| Deserialize | Standard | 1488 | 62.98% |
| Custom | 913 |