-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Inspect module is prohibitively expensive to import #117865
Comments
It looks like the bulk of the import time is spent in
If those imports could be deferred, that would likely address the concern. |
Visualised with https://github.com/nschloe/tuna: ./python.exe -X importtime -c 'import inspect' 2> /dev/null ; ./python.exe -X importtime -c 'import inspect' 2> import.log && tuna import.log |
Some notes:
|
yeah, I looked at this in the past and decided that it wasn't realistically possible to improve this situation without either heavily refactoring |
I think we can get rid of the |
|
A bunch of the |
The half of the |
Using a tool I have for lazy imports/exports I did some quick testing on deferring the imports for This involved making My machine isn't stable enough for really consistent testing but this gives a rough idea of the result. Benchmarks 4 and 5 include actually creating a dataclass. The Results from today's main
Results from lazy_inspect
Footnotes |
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it.
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it. Co-authored-by: Alex Waygood <[email protected]>
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it. Co-authored-by: Alex Waygood <[email protected]>
From post by @AlexWaygood in #117372 (comment)_:
Perhaps inspect could be refactored to limit the import-time cost.
Currently on my m3 mac pro, on the second attempt, the import times are 1.2ms and 7.9ms (cumulative):
I've searched the issue tracker and didn't see anything tracking this concern, so right now it's a naïve feature request.
Related: #108901
Linked PRs
The text was updated successfully, but these errors were encountered: