microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 767 forks source link

Pylance takes 2+ minutes to analyze every change. #6140

Open asparagusbeef opened 1 month ago

asparagusbeef commented 1 month ago

Environment data

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:

  1. When opening the entire project (multi-root workspace with 17 roots)
  2. When opening just a single package which is widely installed, for example the company-commons package.

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:

  1. Open the dispatcher.py in the company-commons workspace, and wait for the logs to stop and analysis to complete.
  2. 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

debonte commented 1 month ago

Can you provide us with access to your code so we can attempt to reproduce this behavior?

asparagusbeef commented 1 month ago

I am sorry, I cannot. This is a very large private code base. It does not happen in isolation, only when everything interacts.

debonte commented 1 month ago

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

asparagusbeef commented 1 month ago

Sure. I reproduced using the same process:

  1. Open the dispatcher.py in the company-commons workspace, and wait for the logs to stop and analysis to complete.
  2. 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!

debonte commented 1 month ago

@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.

debonte commented 1 month ago

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?

heejaechang commented 3 weeks ago

@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.

...

  1. close all open files
  2. make sure to set python.analysis.diagnosticMode to OpenFileOnly, set python.analysis.typeCheckingMode to off and set python.analysis.indexing to false, and python.analysis.enablePytestSupport to false
  3. set settings following this Collecting type evaluation related data in the log
  4. open a file that repro the issue. make sure you open 1 file.
  5. go to the line you will use to repro the issue.
  6. wait vscode to go idle
  7. clear all log in the python language server output window
  8. type a char that will repo your issue. make sure you type 1 char that will start new analysis.
  9. wait vscode to go idle
  10. copy everything in the python language server output 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.