requests icon indicating copy to clipboard operation
requests copied to clipboard

Import time regression

Open holmanb opened this issue 1 year ago • 2 comments

Between 2.31.0 and 2.32.3, import time increased by ~25%. This appears to have been caused by https://github.com/psf/requests/pull/6667, which changed the expensive load_verify_locations() to run at import time (in 2.32.0).

Reproduction Steps

Compare import time of versions with:

$ python3 -X importtime -c 'import requests' 2> requests_import.log
$ tuna requests_import.log

2.31.0

image

2.32.3:

image

holmanb avatar Aug 15 '24 12:08 holmanb

I'm on Windows, with Python 3.11 and requests 2.32.3 and noticed very slow import times and narrowed it down to requests. In my case when importing requests, the requests.adapters module made up 4.353 s (85.9%) of the import time with similar command as above.

donno avatar Nov 01 '24 13:11 donno

We noticed that this slows down yt-dlp startup time by ~50%.

Image

yt-dlp provides its own SSLContext, so the one created by requests on import remains unused.

Is it still planned to revert the caching of a default SSLContext (#6767) or should the SSLContext no longer be created on import as proposed in #6791?

seproDev avatar Feb 07 '25 10:02 seproDev

It sounds like this may be fixed in https://github.com/psf/requests/pull/6767, but I will leave this open until released to confirm.

holmanb avatar Jun 13 '25 17:06 holmanb