1

I have a really big chunk of JSON i'm deserializing with Newtonsoft.json

Users.UserDataDict response = JsonConvert.DeserializeObject<Users.UserDataDict>(teststring);

I notice that the first time I call this method it's really slow (hundreds of milliseconds longer than it needs to be). So what I'm doing is calling it when the app starts on some large dummy data in so that when the user is interacting with the app it's not slow. Is there anyway I can just initialize it properly or increase it's buffer size or whatever needs done rather than calling it on start up on some really large data?

4
  • Here are some tips on how to improve performance when working with big JSON data: newtonsoft.com/json/help/html/performance.htm Commented Aug 12, 2016 at 20:17
  • The first time you deserialize, required DLLs might be loaded; various methods might get JITted; type initializers might get called; and Json.NET will generate and cache contract information as described here. To "warm up" the serializer you don't need to deserialize a large chunk of dummy data, you probably just need to generate contracts for each type to be deserialized. Commented Aug 12, 2016 at 20:42
  • If you have control over the API that you are consuming the service from, you can paginate the data so that you increase throughput. The data will come in pages of 20 items per page. So you can get the first 20 items, display them to the user then load the rest and add to the initial list. Commented Aug 12, 2016 at 20:59
  • Thanks for your help guys! Commented Aug 16, 2016 at 16:54

1 Answer 1

1

Seems that JsonConvert caches each type to be de-/serialized. Based on that the first call to JsonConvert.SerializeObject/JsonConvert.DeserializeObject may take "longer". A more detailed answer can be found here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks :-) That was what I concluded as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.