Bug 15088 - HttpClient is slower than HttpsURLConnection and AndroidHttpClient on initial HTTPS request
Summary: HttpClient is slower than HttpsURLConnection and AndroidHttpClient on initial...
Status: RESOLVED FEATURE
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
URL:
Depends on:
Blocks:
 
Reported: 2013-09-30 20:50 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-10-12 12:49 UTC (History)
6 users (show)

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


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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

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