Skip to content

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.
@JukkaL JukkaL requested a review from ilevkivskyi December 21, 2022 14:21
@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.

3 participants