This project is read-only.

Poor performance when using HttpContent.ReadAsAsync<T> for JSON payloads

Topics: ASP.NET Web API, General
Oct 21, 2014 at 10:18 PM
Edited Oct 21, 2014 at 10:20 PM

I have been doing some performance analysis for the APIs we are building which are heavily based on ASP.NET Web API and HttpClient and I noticed very high CPU usage mainly around serialisation and deserialisation of JSON payloads. This by itself not a biggie until I discovered if I use ReadAsStringAsync and then deserialise, performance is much better.

I have documented my observations here and got in touch with James Newton King, author of Json.NET.

Should I raise a bug in Microsoft connect or this level of engagement is enough? Also wondering what your thoughts are - does this make any sense? I could be doing something completely wrong.

Oct 21, 2014 at 10:24 PM
Hi aliostad,

My guess is that your issue might have already been solved by the following fix which was made very recently. Check it out and let us know if you have any more questions:



If you cannot take this fix, probably you can try the workaround where you cache the Json formatter and use it explicitly when doing a ReadAsAsync with your HttpClient.

Oct 21, 2014 at 11:21 PM

It makes sense and seems to be the same problem.
Oct 21, 2014 at 11:29 PM
Cool...Thanks! for reporting the issue and the detailed analysis...
Jul 18, 2016 at 10:59 AM
Edited Jul 18, 2016 at 10:59 AM
Thanks Guys.

It fixed one our performance issue