8000 Speed up caching of subtype checks by JukkaL · Pull Request #12539 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Speed up caching of subtype checks #12539

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 3 commits into from
Apr 7, 2022
Merged

Conversation

JukkaL
Copy link
Collaborator
@JukkaL JukkaL commented Apr 7, 2022

This is very performance critical. Implement a few micro-optimizations
to speed caching a bit. In particular, we use dict.get to reduce the
number of dict lookups required, and avoid tuple concatenation which
tends to be a bit slow, as it has to construct temporary objects.

It would probably be even better to avoid using tuples as keys
altogether. This could be a reasonable follow-up improvement.

Avoid caching if last known value is set, since it reduces the
likelihood of cache hits a lot, because the space of literal values
is big (essentially infinite).

Also make the global strict_optional attribute an instance-level
attribute for faster access, as we might now use it more frequently.

I extracted the cached subtype check code into a microbenchmark
and the new implementation seems about twice as fast (in an
artificial setting, though).

Work on #12526 (but should generally make things a little better).

JukkaL added 3 commits April 7, 2022 13:37
This is very performance critical. Implement a few micro-optimizations
to speed caching a bit. In particular, we use dict.get to reduce the
number of dict lookups required, and avoid tuple concatenation which
tends to be a bit slow, as it has to construct temporary objects.

It would probably be even better to avoid using tuples as keys
altogether. This could be a reasonable follow-up improvement.
@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor
github-actions bot commented Apr 7, 2022

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

JukkaL added a commit that referenced this pull request Apr 7, 2022
This tweaks a change made in #12539 that may have slowed things
down. The behavior introduced in the PR was more correct, but it's not
worth a potential major performance regression, since union
simplification is not something we have to get always right for
correctness.

Work on #12526.
@JukkaL JukkaL merged commit cddd819 into master Apr 7, 2022
@JukkaL JukkaL deleted the faster-cached-subtype-check2 branch April 7, 2022 17:55
JukkaL added a commit that referenced this pull request Apr 7, 2022
This tweaks a change made in #12539 that may have slowed things
down. The behavior introduced in the PR was more correct, but it's not
worth a potential major performance regression, since union
simplification is not something we have to get always right for
correctness.

Work on #12526.
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
0