Title: gh-118761: Improve import time of `subprocess` by hukkin · Pull Request #129427 · python/cpython · GitHub
Open Graph Title: gh-118761: Improve import time of `subprocess` by hukkin · Pull Request #129427 · python/cpython
X Title: gh-118761: Improve import time of `subprocess` by hukkin · Pull Request #129427 · python/cpython
Description: This makes import subprocess lazy import locale and signal. As a result, also re (imported by locale) and enum (imported by signal) imports are skipped. Benchmark import time main branch $ hyperfine --warmup 11 "./python -c 'import subprocess'" "./python -c 'pass'" Benchmark 1: ./python -c 'import subprocess' Time (mean ± σ): 24.6 ms ± 0.9 ms [User: 20.8 ms, System: 4.0 ms] Range (min … max): 23.5 ms … 28.0 ms 108 runs Benchmark 2: ./python -c 'pass' Time (mean ± σ): 10.8 ms ± 0.6 ms [User: 8.9 ms, System: 2.3 ms] Range (min … max): 10.1 ms … 14.2 ms 190 runs Summary './python -c 'pass'' ran 2.28 ± 0.16 times faster than './python -c 'import subprocess'' PR branch $ hyperfine --warmup 11 "./python -c 'import subprocess'" "./python -c 'pass'" Benchmark 1: ./python -c 'import subprocess' Time (mean ± σ): 18.7 ms ± 0.8 ms [User: 16.1 ms, System: 3.2 ms] Range (min … max): 17.6 ms … 21.7 ms 139 runs Benchmark 2: ./python -c 'pass' Time (mean ± σ): 10.4 ms ± 0.5 ms [User: 9.4 ms, System: 1.8 ms] Range (min … max): 9.7 ms … 12.9 ms 226 runs Summary './python -c 'pass'' ran 1.80 ± 0.11 times faster than './python -c 'import subprocess'' Benchmark subprocess.run call In fact, this not only has an effect on import time, but simple subprocess.run calls, too: main branch $ hyperfine --warmup 11 "./python -c 'import subprocess; subprocess.run([\"sleep\", \"0\"])'" "./python -c 'pass'" Benchmark 1: ./python -c 'import subprocess; subprocess.run(["sleep", "0"])' Time (mean ± σ): 26.7 ms ± 1.1 ms [User: 23.4 ms, System: 3.4 ms] Range (min … max): 25.5 ms … 31.7 ms 103 runs Benchmark 2: ./python -c 'pass' Time (mean ± σ): 11.7 ms ± 0.8 ms [User: 9.5 ms, System: 2.4 ms] Range (min … max): 10.9 ms … 15.4 ms 235 runs Summary './python -c 'pass'' ran 2.28 ± 0.18 times faster than './python -c 'import subprocess; subprocess.run(["sleep", "0"])'' PR branch $ hyperfine --warmup 11 "./python -c 'import subprocess; subprocess.run([\"sleep\", \"0\"])'" "./python -c 'pass'" Benchmark 1: ./python -c 'import subprocess; subprocess.run(["sleep", "0"])' Time (mean ± σ): 22.0 ms ± 1.3 ms [User: 18.1 ms, System: 3.9 ms] Range (min … max): 20.3 ms … 27.2 ms 119 runs Benchmark 2: ./python -c 'pass' Time (mean ± σ): 12.0 ms ± 0.4 ms [User: 9.8 ms, System: 2.3 ms] Range (min … max): 11.5 ms … 13.6 ms 224 runs Summary './python -c 'pass'' ran 1.84 ± 0.12 times faster than './python -c 'import subprocess; subprocess.run(["sleep", "0"])'' Issue: gh-118761
Open Graph Description: This makes import subprocess lazy import locale and signal. As a result, also re (imported by locale) and enum (imported by signal) imports are skipped. Benchmark import time main branch $ hyperfin...
X Description: This makes import subprocess lazy import locale and signal. As a result, also re (imported by locale) and enum (imported by signal) imports are skipped. Benchmark import time main branch $ hyperfin...
Opengraph URL: https://github.com/python/cpython/pull/129427
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:8ea21495-d630-5156-afcf-9e7687ef71c8 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | A108:3350DE:933CB:C8862:6969C3C3 |
| html-safe-nonce | bb3f3ba88ee83dbbf6088b79ae23c7af2490b086452b2c5f8bfe3e2633a79185 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTA4OjMzNTBERTo5MzNDQjpDODg2Mjo2OTY5QzNDMyIsInZpc2l0b3JfaWQiOiIyNTQwNTA5MDE2MDM0NDkzMzc5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7b44ff63d9fc9dc9c3a99e24fea2ce0943eb5519c51062e9114e39d94492d97a |
| hovercard-subject-tag | pull_request:2304016188 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/129427/checks |
| twitter:image | https://avatars.githubusercontent.com/u/3275109?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3275109?s=400&v=4 |
| og:image:alt | This makes import subprocess lazy import locale and signal. As a result, also re (imported by locale) and enum (imported by signal) imports are skipped. Benchmark import time main branch $ hyperfin... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-cache |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width