-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Minor proper subtype check optimization #12536
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
Conversation
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.
This comment has been minimized.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This comment has been minimized.
This comment has been minimized.
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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 nestedfunction to avoid this overhead.
Work on #12526.