Skip to content
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

Minor proper subtype check optimization #12536

Merged
merged 3 commits into from
Apr 7, 2022
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Apr 7, 2022

Mypyc is bad at compiling nested functions. In one use case
we were spending 7% of the mypy runtime just creating closure
objects for check_argument. Here I manually inline the nested
function to avoid this overhead.

Work on #12526.

Mypyc is bad at compiling nested functions. In one use case
we were spending 7% of the mypy runtime just creating closure
objects for `check_argument`. Here I manually inline the nested
function to avoid this overhead.

Work on #12526.
@github-actions

This comment has been minimized.

mypy/subtypes.py Outdated
elif variance == CONTRAVARIANT:
nominal = nominal and self._is_proper_subtype(ra, ta)
else:
nominal = nominal and mypy.sametypes.is_same_type(ta, ra)
else:
nominal = nominal and mypy.sametypes.is_same_type(ta, ra)
Copy link
Member

Choose a reason for hiding this comment

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

What about adding if nominal: break here? Looks like we're needlessly rerunning the loop if a previous iteration already set nominal = True

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are doing nominal and ... so a further iteration could still make it false?

Copy link
Member

Choose a reason for hiding this comment

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

Ah true, I misread. But then we can break immediately if anything sets it to False, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That seems to be the case. I'll update this.

mypy/subtypes.py Outdated Show resolved Hide resolved
Co-authored-by: Jelle Zijlstra <[email protected]>
@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JukkaL JukkaL merged commit 222029b into master Apr 7, 2022
@JukkaL JukkaL deleted the speed-up-proper-subtypes branch April 7, 2022 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants