Skip to content

fix: faster CLI on Python 3.15#2797

Draft
henryiii wants to merge 1 commit intopypa:mainfrom
henryiii:henryiii/chore/fasthelp
Draft

fix: faster CLI on Python 3.15#2797
henryiii wants to merge 1 commit intopypa:mainfrom
henryiii:henryiii/chore/fasthelp

Conversation

@henryiii
Copy link
Contributor

@henryiii henryiii commented Mar 24, 2026

This makes running cibuildwheel --help or cibuildwheel --print-build-indentifiers around 3-4x faster on Python 3.15a7 by making imports lazy. If using uv on a first run (like with uvx), this likely is even more, since it doesn't pre-compile .pyc files by default.

I used my flake8-lazy package (post here) to come up with the
__lazy_modules__ lists, and GPT 5 (due to the 0x token usage) in VSCode's copilot to apply the lists to the files.

I restored from __future__ import annotations, but maybe I didn't need to, since they are not resolved on 3.14+. I might try without too later. I think it's fine, but #2799 and #2798 were exposed while trying this. Will minimize the diff after those.

Edit: used the new --apply feature of flake8-lazy to create this instead.

Benchmark 1: .venv/bin/python3.14 -m cibuildwheel -h Time (mean ± σ): 250.7 ms ± 5.2 ms [User: 201.2 ms, System: 28.9 ms] Range (min … max): 243.1 ms … 258.9 ms 11 runs Benchmark 1: .venv/bin/python3.15 -m cibuildwheel -h Time (mean ± σ): 59.4 ms ± 4.6 ms [User: 48.0 ms, System: 8.5 ms] Range (min … max): 55.6 ms … 80.3 ms 49 runs 
Benchmark 1: .venv/bin/python3.14 -m cibuildwheel --print-build-identifiers Time (mean ± σ): 249.9 ms ± 4.3 ms [User: 199.5 ms, System: 27.4 ms] Range (min … max): 242.8 ms … 258.3 ms 11 runs Benchmark 1: .venv/bin/python3.15 -m cibuildwheel --print-build-identifiers Time (mean ± σ): 64.8 ms ± 1.0 ms [User: 53.5 ms, System: 9.0 ms] Range (min … max): 63.4 ms … 68.0 ms 41 runs 

Here's the version with @hugovk's CPython fix (thanks to @hugovk!):

$ hyperfine --warmup 10 \ "./python.exe -m cibuildwheel --help" \ "PYTHON_LAZY_IMPORTS=none ./python.exe -m cibuildwheel --help" Benchmark 1: ./python.exe -m cibuildwheel --help Time (mean ± σ): 56.2 ms ± 1.5 ms [User: 46.5 ms, System: 8.6 ms] Range (min … max): 53.6 ms … 62.3 ms 50 runs Benchmark 2: PYTHON_LAZY_IMPORTS=none ./python.exe -m cibuildwheel --help Time (mean ± σ): 173.9 ms ± 2.3 ms [User: 151.8 ms, System: 19.9 ms] Range (min … max): 169.9 ms … 177.5 ms 17 runs Summary ./python.exe -m cibuildwheel --help ran 3.09 ± 0.09 times faster than PYTHON_LAZY_IMPORTS=none ./python.exe -m cibuildwheel --help 
@hugovk
Copy link
Contributor

hugovk commented Mar 25, 2026

henryiii#17 defers more imports to be 1.4x faster than this PR and 4x faster than upstream main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants