-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Mypy micro-optimizations (batch 3/3) #19770
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
This comment has been minimized.
This comment has been minimized.
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.
would _is_subtype = is_proper_subtype if overlap_for_overloads else is_subtype
be fast enough since we don't allocate a function object? would be more readable
@hauntsaninja That will be still slower because the only way you can an "unknown" |
yes it'll be slower, but should be much faster than allocating a new function object while keeping things more readable. don't feel strongly though and i didn't measure |
mypy/meet.py
Outdated
if is_subtype(left, right, ignore_promotions=ignore_promotions) or is_subtype( | ||
right, left, ignore_promotions=ignore_promotions | ||
): | ||
return 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.
One possible way to de-uglify this is to move this whole chunk to a new function outside (say overlap_simple()
), and re-use it below. This way it will at least not appear twice.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Several mypy micro-optimizations. Together with batches 1 and 2 these improve self check performance by 1.8%.
This mostly avoids some allocations of nested function objects.