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 type parameter checks in subtype checking #14324

Merged
merged 1 commit into from
Dec 20, 2022
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Dec 20, 2022

Avoid the use of a nested function, which are a bit slow when compiled with mypyc. Also avoid a callable value and instead call a function directly, which allows using faster native calls.

Based on a quick experiment, this speeds up self check by about 3%.

This addresses some of the slowdown introduced in #13303.

Avoid the use of a nested function, which are a bit slow when compiled
with mypyc. Also avoid a callable value and instead call a function
directly, which allows using faster native calls.

Based on a quick experiment, this speeds up self check by about 3%.

This addresses some of the slowdown introduced in #13303.
JukkaL added a commit that referenced this pull request 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 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!
Though we could also just move them to be normal top level functions.

@JukkaL JukkaL merged commit d35e571 into master Dec 20, 2022
@JukkaL JukkaL deleted the faster-subtype-3 branch December 20, 2022 15:45
JukkaL added a commit that referenced this pull request 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.
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.

2 participants