Bug 15088 - HttpClient is slower than HttpsURLConnection and AndroidHttpClient on initial HTTPS request
Summary: HttpClient is slower than HttpsURLConnection and AndroidHttpClient on initial...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-30 20:50 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-10-12 12:49 UTC (History)
6 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Test case (13.78 KB, application/zip)
2013-09-30 20:50 UTC, Brendan Zagaeski (Xamarin Team, assistant)

Description Brendan Zagaeski (Xamarin Team, assistant) 2013-09-30 20:50:24 UTC
Created attachment 5027 [details]
Test case

Reported on behalf of a user.

## Steps to reproduce
1. Open and run the attached test case.
2. Push the "Click" button.
3. Notice how long the app takes before writing the response into the TextView.
4. Stop the app.
5. Uncomment one of the "Using HttpsURLConnection" or "Using AndroidHttpClient" regions, and comment out the "Using HttpClient" region.
6. Run the app again, and repeat steps 2 and 3.

## Result
`HttpsURLConnection` and `AndroidHttpClient` complete the request noticeably more quickly than `HttpClient`.

## Additional information

- At least in the user's full app, compiling in release mode and running on-device did not change the result.

- Plain HTTP requests are markedly faster than HTTPS requests. If there is a difference between `HttpClient` and the other options when performing HTTP requests, it is difficult to notice.

- Clicking the button a second time will send a second HTTPS request to a different server. If you switch the "google" and "facebook" URLs, the second ("google") request completes more quickly than when the "google" request runs first. This might vaguely suggest the involvement of a reverse DNS lookup bug from Android [1], except that:

  1. The project is currently set to use Jelly Bean, so the bug should be fixed.
  2. The "Using AndroidHttpClient" version shows no problem.

[1] https://code.google.com/p/android/issues/detail?id=13117#c14

## Version information
Xamarin.Android 4.8.3
Comment 2 Jonathan Pryor 2014-07-28 17:45:53 UTC
Sounds like a JIT overhead issue.

This should be improved slightly in 4.14 (by moving much of the HTTPS stack into mscorlib.dll), but even then this will require JIT'ing the entire HTTPS stack in order to make the initial request -- Security, crypto, etc., etc. -- all of which the Android types won't require.

This will be improved once we offer AOT support.
Comment 4 Marek Safar 2017-10-12 12:49:58 UTC
This is expected, full managed implementation will be always slower than implementation which reuses native parts.

We could try to look into making the code faster but as we already have fast (AndroidHttpClient) implementation available I don't strong motivation to do it

Note You need to log in before you can comment on or make changes to this bug.