Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize import time by deferring SSL context creation #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dosine-staging[bot]
Copy link

This pull request addresses the import time regression issue identified between versions 2.31.0 and 2.32.3 of the library. The regression was caused by the load_verify_locations() function being executed at import time, as introduced in PR psf#6667.

Changes Made:

  • Moved the creation and loading of the SSL context to a new function _get_preloaded_ssl_context(), which is called only when needed, rather than at import time.
  • Updated the _urllib3_request_context function to use the new _get_preloaded_ssl_context() method, ensuring that the SSL context is only created when required.

These changes should reduce the import time by deferring the expensive SSL context creation until it is actually needed, thus resolving the regression issue.

Testing:

To verify the improvement, compare the import times of the affected versions using the provided reproduction steps. This should demonstrate a reduction in import time back to levels similar to version 2.31.0.

Co-authored-by: Genie <genie@cosine.sh>
@dosine-staging dosine-staging bot marked this pull request as ready for review October 14, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant