You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
argparse in 3.14+ is importing _colorize earlier than necessary #148823
This results in a noticeable %-wise increase in the effective import time when you actually use the module. Note that some of this time is also a lazy import of shutil which isn't very lazy either, but that's a separate issue.
Benchmark 1: .venv_313/bin/python -c 'import argparse; argparse.ArgumentParser()'
Time (mean ± σ): 15.6 ms ± 3.0 ms [User: 13.6 ms, System: 2.1 ms]
Range (min … max): 11.3 ms … 27.9 ms 200 runs
Benchmark 2: .venv_314/bin/python -c 'import argparse; argparse.ArgumentParser()'
Time (mean ± σ): 25.2 ms ± 3.6 ms [User: 21.9 ms, System: 3.2 ms]
Range (min … max): 19.9 ms … 39.5 ms 200 runs
Benchmark 3: .venv_315/bin/python -c 'import argparse; argparse.ArgumentParser()'
Time (mean ± σ): 25.7 ms ± 3.2 ms [User: 22.6 ms, System: 3.1 ms]
Range (min … max): 21.0 ms … 34.7 ms 200 runs
Summary
.venv_313/bin/python -c 'import argparse; argparse.ArgumentParser()' ran
1.61 ± 0.39 times faster than .venv_314/bin/python -c 'import argparse; argparse.ArgumentParser()'
1.65 ± 0.38 times faster than .venv_315/bin/python -c 'import argparse; argparse.ArgumentParser()'
This gets a bit more noticeable in real terms on slower devices, so it would be nice to defer this until something actually needs colouring. Note that there are some plans to make _colorize faster, but I'm not sure how much faster it will be as an end result so this may still be worth doing separately to that work.
I meant to note that the shutil import is already present in 3.13, hence being a separate issue - but it has gotten slightly slower due to the addition of compression.zstd which it now imports.
Activity
DavidCEllis commentedon Apr 21, 2026
I meant to note that the
shutilimport is already present in 3.13, hence being a separate issue - but it has gotten slightly slower due to the addition ofcompression.zstdwhich it now imports.gh-148823: Avoid importing `_colorize` when creating an `ArgumentPars…
DavidCEllis commentedon May 6, 2026
Closed by #148827