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

Defer import of json and platform #503

Merged
merged 6 commits into from
Sep 11, 2024
Merged

Defer import of json and platform #503

merged 6 commits into from
Sep 11, 2024

Conversation

danielhollas
Copy link
Contributor

Staged on top of #502

platform and json modules take together around 1.5ms to import, around 10% of total import time. Since they are both used in a single place it probably makes sense to inline their import.

After this PR, this is an output of python -Ximporttime -c "import importlib_metadata" visualized with tuna using cpython main branch.

image

@jaraco
Copy link
Member

jaraco commented Sep 11, 2024

Attempting to disentangle the performance impacts of json and platform:

 importlib_metadata main 🐚 .tox/py/bin/python -Ximporttime -c "import importlib_metadata" 2>1 | grep -E r'platform|\sjson$|importlib_metadata$'
import time:        89 |        800 |   json
import time:       221 |        251 |     platform
import time:       636 |      13692 | importlib_metadata
 importlib_metadata main 🐚 800/13692
0.05842827928717499
 importlib_metadata main 🐚 251/13692
0.018331872626351154

I see json accounts for ~6% of the startup and platform under 2% (on my machine under Python 3.12).

@jaraco jaraco merged commit 8b909f9 into python:main Sep 11, 2024
12 checks passed
@danielhollas danielhollas deleted the defer-json branch September 11, 2024 14:27
@danielhollas danielhollas changed the title Defer import of json and zipp Defer import of json and platform Sep 11, 2024
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

Successfully merging this pull request may close these issues.

2 participants