Skip to content

Cache common instances #19621

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
Aug 9, 2025
Merged

Cache common instances #19621

merged 3 commits into from
Aug 9, 2025

Conversation

ilevkivskyi
Copy link
Member

These few types account for a significant proportion of all types created:

  • str is just everywhere
  • object and function are used as fallbacks in many places
  • int and bool are coming from various literals

This gives around 1.5% performance improvement on my desktop. This is a bit ugly, but also looks like an easy win. Note that during semantic analysis I am caching types more conservatively, just in case some plugins modify them in place (named_type() is a part of semantic analyzer plugin interface).

Copy link
Contributor

github-actions bot commented Aug 9, 2025

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

@ilevkivskyi ilevkivskyi merged commit cc5f1e1 into python:master Aug 9, 2025
20 checks passed
@ilevkivskyi ilevkivskyi deleted the tst-prf-1 branch August 9, 2025 08:09
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