Skip to content

perf: add __slots__ to SubtypeVisitor #19394

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

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

sterliakov
Copy link
Collaborator

We construct quite a lot of them. This made a selfcheck benchmark 0.4-0.7% faster when run on my local PC.

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.

Great!

Copy link
Contributor

github-actions bot commented Jul 7, 2025

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

@hauntsaninja hauntsaninja merged commit afd5a38 into python:master Jul 7, 2025
19 checks passed
"options",
"_subtype_kind",
)

def __init__(self, right: Type, subtype_context: SubtypeContext, proper_subtype: bool) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

If a lot of SubtypeVisitor objects are created, it follows that a lot of SubtypeContext must also be created to pass into it, so I think adding __slots__ to SubtypeContext here should also yield some further improvement.

Copy link
Contributor

Choose a reason for hiding this comment

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

See #19397

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