Pylance takes 2+ minutes to analyze every change.
Environment data
- Language Server version: v2024.7.1
- OS and version: Windows 11
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.11.5
Code Snippet
Cannot provide a code snippet as this happens in a large project with multiple workspaces.
Repro Steps
My project consists of 11 services that use 6 private packages (installed with pip install --editable)
This happens in two scenarios:
- When opening the entire project (multi-root workspace with 17 roots)
- When opening just a single package which is widely installed, for example the
company-commonspackage.
Note that scenario 2 doesn't happen when a package is installed with regular pip install.
Expected behavior
I understand this is a large project, but I'm pretty sure my computer should be able to handle it at least an acceptable latency.
Actual behavior
It's excruciatingly slow. Sometimes over 2+ minutes for a small change.
Logs
My process for those logs was:
- Open the
dispatcher.pyin thecompany-commonsworkspace, and wait for the logs to stop and analysis to complete. - Make a small change, and wait for the logs to stop and analysis to complete, including hovering my mouse over a function to ensure its resolved.
https://pastebin.com/gRp7x9bd
Can you provide us with access to your code so we can attempt to reproduce this behavior?
I am sorry, I cannot. This is a very large private code base. It does not happen in isolation, only when everything interacts.
I am sorry, I cannot. This is a very large private code base. It does not happen in isolation, only when everything interacts.
In that case, can you please collect a CPU profile of the issue? The profile may contain enough information for us to track down the underlying issue. There are instructions on how to do this here: https://github.com/microsoft/pylance-release/wiki/Collecting-data-for-an-investigation.#collecting-cpuprofiles
Sure. I reproduced using the same process:
- Open the
dispatcher.pyin thecompany-commonsworkspace, and wait for the logs to stop and analysis to complete. - Make a small change, and wait for the logs to stop and analysis to complete, including hovering my mouse over a function to ensure its resolved.
Note that I waited long minutes at idle parts (I made the change, left the computer for a while, not sure how long, then stopped profilling).
Profiling:
https://file.io/GdDwL3YyadCA
Logs (no tracing)
https://pastebin.com/vQW5z08C
Thanks!
@asparagusbeef, thanks for the CPU profiles. Unfortunately I'm unable to load the ones that are most interesting, and my best guess is that I'm hitting a VS Code bug there. I filed https://github.com/microsoft/vscode/issues/223565. I'm blocked on analyzing your files until I hear back from the VS Code team on this.
Note that I waited long minutes at idle parts (I made the change, left the computer for a while, not sure how long, then stopped profilling).
@asparagusbeef, since the size of these files seems to be causing problems for profile viewers, could you try generating a new set of profiles and minimizing the duration of the recording?
@asparagusbeef I have another idea to figure out the perf cause. since the log shows some files takes long time to analyze, how about you provide us this log (https://github.com/microsoft/pylance-release/wiki/Collecting-data-for-an-investigation.#collecting-type-evaluation-related-data-in-the-log)
if you can do this and provide log for us, that will provide us best chance to find out what is causing perf issue.
...
- close all open files
- make sure to set
python.analysis.diagnosticModetoOpenFileOnly, setpython.analysis.typeCheckingModetooffand setpython.analysis.indexingtofalse, andpython.analysis.enablePytestSupporttofalse - set settings following this Collecting type evaluation related data in the log
- open a file that repro the issue. make sure you open 1 file.
- go to the line you will use to repro the issue.
- wait vscode to go idle
- clear all log in the
python language serveroutput window - type a char that will repo your issue. make sure you type 1 char that will start new analysis.
- wait vscode to go idle
- copy everything in the
python language serveroutput window, and provide them with us.
...
my gut feeling is some of your code require a lot of time for us to infer types. so if you provide type hints at some strategic points, that might improve overall perf.
This issue has been closed automatically because it needs more information and has not had recent activity. If the issue still persists, please reopen with the information requested. Thanks.