GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — gh-154675: Use lazy imports in json package by brittanyrey · Pull Request #156801 · python/cpython Conversation
|
| before | after | |
|---|---|---|
python -c "import json.tool" |
41.09 ms | 21.24 ms (−48%) |
python -c "import json" |
20.98 ms | 20.81 ms (−0.8%, neutral) |
python -m json.tool f.json |
46.06 ms | 45.87 ms (−0.4%, neutral) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
`argparse` and `_colorize` are only needed once `main()` runs, so import them lazily. Also hoist the nested `warnings._deprecated` import in `json.__getattr__` up to a module-level `lazy from`. `python -c "import json.tool"` drops from 41.1 ms to 21.2 ms (-48%): interleaved A/B, median of 9 rounds of min-of-25 runs, same binary with `Lib/json` swapped via `PYTHONPATH`; an unrelated `import csv` control moved +0.2%. Running the CLI is unchanged -- `main()` always builds an `ArgumentParser` and always calls `can_colorize()`, so both modules still get imported.
There was an error while loading. Please reload this page.
|
Are there any use cases where the improved import time matters? Users importing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Don't think so. And |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
AFAIR, the PEP explicitly said that we do not want to mechanically convert everything to lazy imports. Considering the noise for json itself I wonder about this change. json.tool is likely to be used as a CLI and there is no reason to do "import json.tool" as the public API is empty IIRC |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…q7vZ2.rst Co-authored-by: Pieter Eendebak <[email protected]>
|
Solid call out. Dug in and I completely see what you mean... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll close then 👍🏽 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.