Speed up startup time by avoiding CLI import #3523
Unanswered
natehardison
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Importing the
_main.pymodule inhttpx/__init__.pyadds 0.087s worth of import time on my machine (MacBook M1 Pro, 32 GB RAM, macOS 15.3.1) running Python 3.13.2.It's certainly not a huge amount of time in the absolute, but it roughly doubles the amount of time it takes to
import httpx, even when you're not intending to run the CLI. Here's an import time graph generated using tuna on the output ofpython -X importtime -c "import httpx" > import.logA possible fix is to add
httpx/__main__.pythat does the import instead. This would also allowpython -m httpxas in #3216. I did a quick proof of concept here: master...natehardison:httpx:masterIt does change the public API:
httpx.mainbecomes the (more ungainly)httpx.__main__.main.Beta Was this translation helpful? Give feedback.
All reactions