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 — Speed up import time by deferring inspect by danielhollas · Pull Request #499 · python/importlib_metadata Conversation
|
| return top if rest else None | ||
|
|
||
|
|
||
| inspect = None |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is a trick that is used in stdlib. I am not sure it is needed here, but since get_toplevel_name is called in a loop from _top_level_inferred perhaps it is warranted to avoid the overhead of calling import inspect repeatedly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of global variables or the additional complexity. This change introduces enough disruption to the essential logical flow that I'm -1. Do we know how much overhead there is in repeated import inspect? My understanding (which may be incorrect) is that import inspect is essentially a dict lookup if it's already been imported. I'm guessing the overhead is acceptable. Can we try a simple deferral for now?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contrib!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return top if rest else None | ||
|
|
||
|
|
||
| inspect = None |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of global variables or the additional complexity. This change introduces enough disruption to the essential logical flow that I'm -1. Do we know how much overhead there is in repeated import inspect? My understanding (which may be incorrect) is that import inspect is essentially a dict lookup if it's already been imported. I'm guessing the overhead is acceptable. Can we try a simple deferral for now?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| global inspect | ||
| if inspect is None: | ||
| import inspect |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since we don't have a test protecting this behavior, I'd like to see a comment pointing to the issue, so a future someone doesn't refactor this optimization away.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- wallrusify - add a note about deffered import
|
I've minimized the change to address the specific issue. I'll deal with the typeshed ignore workaround separately. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I should have added a news fragment before merging. I added it later in 71b4678. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This change is released in v8.4.0. |
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.