Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Aug 31, 2025

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.

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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

@ilevkivskyi
Copy link
Member

@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.

@hauntsaninja
Copy link
Collaborator

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
Copy link
Member

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.

Copy link
Contributor

github-actions bot commented Sep 1, 2025

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL JukkaL merged commit 0afa33d into master Sep 1, 2025
20 checks passed
@JukkaL JukkaL deleted the mypy-opts-2 branch September 1, 2025 13:25
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.

3 participants