-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
MyPy 0.750 slow startup (or hang) on macOS #8055
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
Comments
Can you try installing mypy with the pip flag |
In a different virtualenv where I still have MyPy 0.740 installed and never tried to upgrade it, |
I should be really clear about something, too: This problem appears to be limited to macOS. On both an Ubuntu machine and an Ubuntu Docker container running on my Mac, 0.750 does not exhibit these symptoms. |
Hm, okay that is rather odd. Can you please try |
Whoa. |
Fascinating! My guess is that there is something going on with the startup script that setuptools installs. Can you run |
I can reproduce this on macOS. However, it seems that this only affects the first run:
I can also reproduce the issue on older mypy versions, all the way back to 0.700, so it seems that this may be caused by the environment. Using I'll continue investigating this. @nickwilliams-eventbrite Can you verify if this only affects the first run after installation (as seems to be the case for me), and if this also happens with mypy 0.700? |
I verifed on my MacOS machine that the first run is slow and later ones are OK.(From |
@TH3CHARLie Thanksk for the information! I think I figured out what triggers the behavior on my Mac: the first run is consistently slow if I have Cisco AnyConnect (VPN) running. Here's the behavior I'm observing (I've repeated this a few times, so it probably isn't random):
I still don't undertand why AnyConnect might be causing this. Perhaps something does a network request when starting mypy? I'm going to debug further, now that I have a repro. Can somebody who has experienced the issue try closing all applications (other than your terminal) and see if it helps? Try installing mypy several times, since the first run after closing applications may still be slow. |
@JukkaL quick repro: closed all applications except terminal, install mypy using pip and after installing, turn on/off Wi-Fi:
I have no Cisco AnyConnect but the results indicate that the phenomenon is not closely related to any particular software but some general network requests maybe Some addups: I tried some other packages: |
Based on Here's an extract from
If I'm reading this correctly, most of the time is spent in XProtect. Looking at the output more generally, it seems that importing modules is slow. There is no particular single thing which takes a lot of time, but many somewhat slow operations (since there are many C extensions). My current hypothesis is that XProtect sometimes slows things down, but once it's scanned a file once, it no longer has a performance impact. If I'm correct, I'm not sure if there's anything we can do about this. Maybe Apple will fix the issue in a future macOS update. A simple, partial workaround would be to compile fewer modules, assuming Python modules won't be impacted by this. Some modules aren't performance-sensitive so compiling them isn't very important. |
My investigation still doesn't shed light on why mypy 0.750 would hang forever. It's possible that there are two separate issues. @nickwilliams-eventbrite Can you verify that 0.750 actually hangs forever and is not just extremely slow (e.g. run it with |
@nickwilliams-eventbrite Actually you'd need to run |
I have another hypothesis: this problem/these problems on happen on Catalina. If you can reproduce the problem, it would be interesting to hear which version of macOS you are running. |
@JukkaL macOS 10.15.1 Catalina |
Maybe I can help as well: I'm on MacOS Catalina 10.15.2 Running
Subsequent runs run fast (normal speed I'm assuming). @JukkaL let me know if you want more debugging runs |
Here's another idea: We currently generate a C extension shim for each compiled module. Maybe the shims could be Python modules instead? This might speed up the initial run on macOS. I created mypyc/mypyc#742 to track this idea. |
Is anybody still seeing this? This seems to have improved in recent macOS releases. If you encounter this, please leave a comment with the macOS version (and mypy version) you are using. |
Indeed using the newest version speeded up |
@JukkaL I still see consistently this with compiled mypy 0.991 and macOS 12.6.1. Initial run takes like 8-15s, subsequent runs take <1s (everything measured with |
Okay, I can't reproduce when running interactively in shell, only when running in a subprocess. Specifically, something like the following should reproduce:
|
My reproducer still takes about 6.5s with mypy 1.5.1 and macOS 13.5. I'm not sure we have a path forward, so closing for now. |
FYI This is still reproducible for me, macOS 15.5 and mypy 1.15.0 $ rm -rf venv && python3.13 -m venv venv && venv/bin/pip install mypy
$ # first time slow
$ time venv/bin/mypy --version
mypy 1.15.0 (compiled: yes)
venv/bin/mypy --version 0.31s user 0.14s system 4% cpu 10.016 total
$ # subsequent times fast
$ time venv/bin/mypy --version
mypy 1.15.0 (compiled: yes)
venv/bin/mypy --version 0.13s user 0.04s system 85% cpu 0.195 total After some print-debugging, the Running as either I can also repro with
I'm not sure why it'd be faster to import these the second time around, as I see |
Yeah still an issue, I guess we should leave the issue open so it's at least more discoverable. But I'm not sure how to work around macOS antivirus |
Are you reporting a bug, or opening a feature request?
Bug report
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
This is not applicable to this bug report.
What is the actual behavior/output?
Running the
mypy .
command hangs forever after upgrading to MyPy 0.750 on macOS. Even tryingmypy --version
to verify the installed version hangs forever. Both commands have to be killed with Ctrl+C (pressing that multiple times is required, actually) after several minutes of waiting for output. Also tried uninstalling and re-installing MyPy from scratch with no luck. Only downgrading to 0.740 solves it from hanging forever, but nowmypy --version
takes about 45 seconds instead of < 1 second like it was before upgrading and downgrading, even though it outputs 0.740. Here is example output of killingmypy --version
under 0.750 after several minutes:What is the behavior/output you expect?
For
mypy .
to run in generally the same amount of time it took previously (~10-15 seconds) and formypy --version
to output and exit instantly, instead of hanging forever like they now do.What are the versions of mypy and Python you are using?
The Python version was installed from Homebrew.
Do you see the same issue after installing mypy from Git master?
If I
pip install git+https://github.com/python/mypy.git@v0.750
,mypy .
works. That's the same version (0.750), just installed from Git instead of PyPi. So this appears to be an issue with the PyPi wheel.What are the mypy flags you are using? (For example --strict-optional)
The text was updated successfully, but these errors were encountered: