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

Question: would a patch deferring the creation of the pre-loaded SSLContext be accepted for faster startup? #6878

Closed
ichard26 opened this issue Feb 1, 2025 · 1 comment

Comments

@ichard26
Copy link

ichard26 commented Feb 1, 2025

Hi,

So I'm investigating ways to improve pip's startup time. Obviously importing a HTTP library like requests is going to be slow regardless of we do, but the deferring the SSLContext pre-loading until use is something would benefit pip.

try:
import ssl # noqa: F401
_preloaded_ssl_context = create_urllib3_context()
_preloaded_ssl_context.load_verify_locations(
extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
)
except ImportError:
# Bypass default SSLContext creation when Python
# interpreter isn't built with the ssl module.
_preloaded_ssl_context = None

pip manages its own SSLContext so it can use truststore for automatic system CA support, thus we never use _preloaded_ssl_context on Python 3.10 or higher1. Unfortunately, OpenSSL 3.x has terrible verify path/location performance: python/cpython#95031 so the unnecessary load_verify_locations() call ends up eating ~15 ms on my system.

So, would a patch deferring the context creation until use be accepted? I realize this is of limited benefit for most users since they probably aren't passing their own SSLContext, so if this is too niche, I understand!

Footnotes

  1. Truststore requires Python 3.10 or higher. Also, pip's truststore integration can be disabled via --use-deprecated=legacy-certs but as the flag name implies, we don't really want people to be using this until necessary.

@ichard26
Copy link
Author

ichard26 commented Feb 1, 2025

Ah, there is already an issue and PR for this. Funnily enough, I 👍 the issue, but I totally forgot about it. Sorry!

@ichard26 ichard26 closed this as completed Feb 1, 2025
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

No branches or pull requests

1 participant