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 #100

Closed
wants to merge 1 commit into from

Conversation

dosine-staging[bot]
Copy link

@dosine-staging dosine-staging bot commented Sep 2, 2024

This pull request addresses the issue of increased import time caused by the changes in psf#6667. The primary change involves deferring the creation of the SSL context until it is actually needed, rather than at import time. This optimization should help reduce the import time by avoiding the expensive load_verify_locations() call during the initial import.

Changes:

  • src/requests/adapters.py: Removed the import and immediate creation of the SSL context. Instead, the SSL context is now created on demand using the new get_ssl_context function.
  • src/requests/utils.py: Added a new function get_ssl_context that creates and caches the SSL context. This function ensures that the SSL context is only created once per interpreter instance, thus optimizing the import time.

These changes should help mitigate the import time regression observed between versions 2.31.0 and 2.32.3.

Co-authored-by: Genie <genie@cosine.sh>
@SamStenner SamStenner closed this Sep 2, 2024
@SamStenner SamStenner deleted the cosine/fix/import-time-increase branch September 2, 2024 14:33
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