Mypy micro-optimizations (batch 3/3) by JukkaL · Pull Request #19770 · python/mypy
Navigation Menu
- Notifications You must be signed in to change notification settings
- Fork 3.2k
Conversation
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.
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" Callable is py_call. The idea is to compile those calls into static calls.
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
| if is_subtype(left, right, ignore_promotions=ignore_promotions) or is_subtype( | ||
| right, left, ignore_promotions=ignore_promotions | ||
| ): | ||
| return True |
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. ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters