Monday, February 26, 2018

Optimize your memory usage when deserializing large JSON objects

During a code review of a customers code base I noticed they were doing a lot of JSON serialization and deserialization actions. As the JSON data was quite large, this caused high memory pressure.  Way to much time was spent in the garbage collector as too many (large) objects were allocated.

To minimize memory usage and the number of objects allocated, Json.NET supports serializing and deserializing directly to a stream.

Here is a code snippet:

No comments: