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

Optimize subtype checking by avoiding a nested function #14325

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Dec 20, 2022

Mypyc isn't good at compiling nested functions, and this one was in one of the hottest code paths in all of mypy. The nested function wasn't even used that often, but mypyc would still construct a closure object every time.

This adds some code duplication, but it's well worth it. Amazingly, this speeds up self-check by about 10%, if my measurements are to be trusted!

This addresses some of the slowdown introduced in #13303. #14324 addresses another related slowdown.

Mypyc isn't good at compiling nested functions, and this one was
in one of the hottest code paths in all of mypy. The nested
function wasn't even used all the time, but mypyc will still
construct a closure object every time.

This adds some code duplication, but it's well worth it. Amazingly,
this speeds up self-check by about 10%!

This addresses some of the slowdown introduced in #13303. #14324
addresses another related slowdown.
@github-actions
Copy link
Contributor

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

Copy link
Collaborator

@svalentin svalentin left a comment

Choose a reason for hiding this comment

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

LGTM

@JukkaL JukkaL merged commit b5fc748 into master Dec 20, 2022
@JukkaL JukkaL deleted the faster-subtype-2 branch December 20, 2022 15:45
@huguesb
Copy link
Contributor

huguesb commented Dec 20, 2022

out of curiosity, why did you pick this verbose/redundant approach instead of the one taken in #14277 ? does mypyc dislike the approach I took there?

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