Cache truststore SSLContext as load_verify_locations() is slow#13199
Cache truststore SSLContext as load_verify_locations() is slow#13199
load_verify_locations() is slow#13199Conversation
SSLContext can be reused across connections as per the Python docs: > SSLContext is designed to be shared and used by multiple connections. > Thus, it is thread-safe as long as it is not reconfigured after being > used by a connection. In addition, requests has been using a global SSLContext and the world hasn't blown up so I'm going to say this is pretty safe.
|
I didn't include a news entry as the benefit is not significant, but when you combine all of the verify location/path loads in a typical run, they consume ~75 ms (~15ms/load) on my system. This eliminates one load from the self-check session, and sethmlarson/truststore#171 will eliminate one load from truststore's intialization. I may include a news entry for the optimization work in general once it's done. |
|
The CPython documentation, requests's experience using a global SSLContext1, and Seth (from the linked truststore PR) all agree this should be fine. I'll merge this now. Footnotes
|
SSLContext can be reused across connections as per the Python docs:
In addition, requests has been using a global SSLContext and the sky hasn't fallen on them so I'm going to say this is pretty safe.
See also python/cpython#95031.