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

[mypyc] Optimize classmethod calls via cls #14789

Merged
merged 6 commits into from
Mar 2, 2023
Merged

[mypyc] Optimize classmethod calls via cls #14789

merged 6 commits into from
Mar 2, 2023

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 26, 2023

If the class has no subclasses, we can statically bind the call target:

class C:
    @classmethod
    def f(cls) -> int:
        return cls.g()  # This can be statically bound, same as C.g()

    @classmethod
    def g(cls) -> int:
        return 1

For this to be safe, also reject assignments to the "cls" argument in
classmethods in compiled code.

This makes the deltablue benchmark about 11% faster.

If the class has no subclasses, we can statically bind the call target.

For this to be safe, also reject assignments to the "cls" argument in
classmethods in compiled code.

This makes the deltablue benchmark about 11% faster.
@github-actions
Copy link
Contributor

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

@JukkaL
Copy link
Collaborator Author

JukkaL commented Feb 26, 2023

Note that we can't easily use vtables to call class methods, since vtables are accessible through instances, not type objects.

@JukkaL JukkaL merged commit 43883fa into master Mar 2, 2023
@JukkaL JukkaL deleted the mypyc-classmethod branch March 2, 2023 10:02
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