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

Speed up the implementation of hasattr() checks #14333

Merged
merged 2 commits into from
Dec 26, 2022
Merged

Speed up the implementation of hasattr() checks #14333

merged 2 commits into from
Dec 26, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Dec 21, 2022

This makes the implementation of hasattr() checks faster (introduced in #13544).

In particular, since the extra_attrs attribute used for hasattr() checks is usually None, I micro-optimized the codepaths to avoid expensive operations whenever there are no hasattr() checks.

Also avoid expensive operations on simple unions and order isinstance checks so that common types are checked first.

I measured a 2% performance uplift in self-check.

This reduces a performance regression. The code path is very
common.
@github-actions
Copy link
Contributor

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

@JukkaL JukkaL merged commit 01a1bf6 into master Dec 26, 2022
@JukkaL JukkaL deleted the faster-hasattr branch December 26, 2022 10:29
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