LampShade
LampShade

Reputation: 2775

Initialize JsonConvert.DeserializeObject

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?

Upvotes: 1

Views: 557

Answers (1)

Moerwald
Moerwald

Reputation: 11304

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.

Upvotes: 1

Related Questions