Skip to content

Python: Limit absolute imports #5791

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

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

tausbn
Copy link
Contributor

@tausbn tausbn commented Apr 27, 2021

Limits the behaviour of #5614 in two ways:

First, we only consider files that are contained in the source archive.
This prevents unnecessary computation involving files in e.g. the
standard library.

Secondly, we ignore any relative imports (e.g. from .foo import ...),
as these only work inside packages anyway.

This fixes an observed performance regression on projects that include
google-cloud-sdk as part of their source code.

As with #5614, I don't think a change note is required.

Limits the behaviour of github#5614 in two ways:

First, we only consider files that are contained in the source archive.
This prevents unnecessary computation involving files in e.g. the
standard library.

Secondly, we ignore any relative imports (e.g. `from .foo import ...`),
as these only work inside packages anyway.

This fixes an observed performance regression on projects that include
`google-cloud-sdk` as part of their source code.
@tausbn tausbn added Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish no-change-note-required This PR does not need a change note labels Apr 27, 2021
@tausbn tausbn requested a review from a team as a code owner April 27, 2021 21:54
@tausbn
Copy link
Contributor Author

tausbn commented Apr 28, 2021

Hmm... I had hoped this limiting of absolute imports would be all that was required, but it seems that evaluation of the MRO is slow even with this change. I guess I'll be adding a few more improvements to this PR.

Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yoff yoff merged commit 73521e2 into github:main Apr 28, 2021
@tausbn
Copy link
Contributor Author

tausbn commented Apr 28, 2021

In case anyone is wondering about yoff's itchy trigger finger 🤠, we discussed this elsewhere: The standard set of tests show no change in performance (which was expected), and a selection of affected projects do.

@tausbn tausbn deleted the python-limit-absolute-imports branch April 28, 2021 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish no-change-note-required This PR does not need a change note Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants