Reputation: 33
I'm working with twitch REST API for education purposes(MVVM pattern) on Windows Phone platform. I noticed pure performance while using HttpClient:
I removed the code because it was draft for prototype.
Like in the answer bellow the problem is in the HttpClient.GetAsync
that resulted in ~671ms execution time.
Upvotes: 1
Views: 228
Reputation: 18102
This has nothing to do with the "performance" of HttpClient
. The reason for this is rather that you're going 10 times to a server to get back some information. That'll be ~768ms per request, which sounds reasonable given some latency. There's little the HttpClient
can do about latency and server response times.
To verify this is the case, I suggest you pop up Fiddler or a similar tool to make sure the response time is the offender. You could also wrap both client.GetAsync
and response.Content.ReadAsAsync<TwitchStream>()
in separate stopwatches and verify that the serialization is not the root cause here.
To decrease the time it takes to get all the needed information, I'd suggest you look into executing the HTTP requests in parallel. HttpClient
is designed to be both reused both for multiple calls, and across multiple threads. So reusing a single instance and executing multiple requests in parallel, using something like Task.WhenAll
or similar, will make it perform better.
Upvotes: 1