Skip to content

Two more micro-optimizations #19627

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

Conversation

ilevkivskyi
Copy link
Member

This has two things (totalling 1.5% locally, but see caveat below):

  • Do not use @contextmanger (that is relatively slow) for local_type_map, since it appears in multiple hot paths.
  • Do not show name suggestions for import errors in third party packages (since those errors are ignored anyway). It calls difflib that can be extremely slow with large modules.

Btw the second will probably not affect self-check, although it did affect my self-check, since apparently pytest depends on numpy. Well, they don't specify it as a package dependency, but https://github.com/pytest-dev/pytest/blob/main/src/_pytest/python_api.py#L17-L18

if TYPE_CHECKING:
    from numpy import ndarray

(and I have numpy installed in all my environments, LOL)

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
Copy link
Member Author

Btw just wanted to brag about how stable is my local bench:

master                    3.810s (0.0%)  | stdev 0.008s 
twop-more-opts            3.756s (-1.4%) | stdev 0.008s 

(you read that right, standard deviation is just 8 milliseconds)

Copy link
Collaborator

@sterliakov sterliakov left a comment

Choose a reason for hiding this comment

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

Nice one! Please post this to plugin API announcements - I expect some plugins in wild might use this functionality (yes, undocumented, yes, private, let's just do that and let people know something might break).

since apparently pytest depends on numpy

Now that was interesting.

@ilevkivskyi ilevkivskyi merged commit 660d911 into python:master Aug 9, 2025
20 checks passed
@ilevkivskyi ilevkivskyi deleted the twop-more-opts branch August 9, 2025 18:47
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