Encrypting and decrypting the HTML content has more overhead than transferring unencrypted content.
There is also overhead in establishing a secure session with the server before the content can then be requested and transferred (request and response are both encrypted).
Also, at the time when the HTTPS request is being made, if OpenSSL has not been loaded yet, there is overhead in loading and initializing the OpenSSL libraries.
Also, you are calling the version of TIdHTTP.Get()
that returns a String
, so all of the downloaded data has to be buffered in memory and then charset-decoded to UTF-16. The larger the HTML is, the more decoding that has to be done.
All of that overhead adds up.
Some things you can do to reduce some of the overhead are:
pre-load OpenSSL beforehand (Indy has a LoadOpenSSLLibrary()
function).
make sure you are re-using HTTP connections to the same server, by using the same TIdHTTP
/TIdSSLIOHandlerSocketOpenSSL
objects, and enabling HTTP keep-alives by setting the TIdHTTP.Request.Connection
property to keep-alive
and/or setting the TIdHTTP.ProtocolVersion
property to pv1_1
(keep-alive is the default behavior in HTTP 1.1, but not in 1.0).
depending on what you are going to do with the downloaded HTML, you might consider downloading it into a TStream
instead of a String
. That way, TIdHTTP.Get()
will skip the caching and charset decoding steps, whatever is downloaded will be saved as-is directly to your provided TStream
. If you don't actually need the HTML at all, you can pass a nil
TStream
to tell Get()
not to cache/process the downloaded data at all.
Also, check to see if sending a request to YouTube is actually generating only one request/response, and not maybe the server using HTTP redirects that cause additional requests to be sent, thus taking more time to reach the final content (see if the TIdHTTP.OnRedirect
event is being triggered or not). Requesting Pixar's homepage is less likely to do that.