GH-109653: Defer import of importlib.metadata._adapters - #109829
Conversation
|
I notice that the description here only mentions Can you confirm how much of the speedup is achieved by each of the two changes? How is timing benchmarked (is it as simple as |
$ python -X importtime -Sc 'import importlib.metadata' 2> importlib_metadata.log
$ cat importlib_metadata.log
$ tuna importlib_metadata.logThe tuna viewer is optional, often I just read the text log. A |
I'll try and come back with some timings A |
|
Here's some timings on macOS (non-debug build with ./python.exe -X importtime -Sc 'import importlib.metadata' 2> importlib_metadata.log && tuna importlib_metadata.logBaseline with
|
jaraco
left a comment
There was a problem hiding this comment.
Thanks hugovk for providing the benchmarks for reference.
I do think we still need comments for these deferred imports to indicate why they're deferred. Without comments or something else to protect them, the optimizations could get normalized away.
|
When you're done making the requested changes, leave the comment: |
|
Cherry-picked to python/importlib_metadata@6673723baa and python/importlib_resources@ca03a4df06. |




For a ~14% speed up. However, this introduces inline imports into
.metadata, which might be undesirable.A