microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 769 forks source link

When inspecting a stdlib method, VSCode consumes high percentage of CPU and becomes unresponsive or very laggy, possibly due to weird Windows Defender interaction #3650

Closed rdbisme closed 1 year ago

rdbisme commented 2 years ago

Environment data

Code Snippet

from zipfile import ZipFile

Repro Steps

Randomly inspecting some stlib methods or classes (e.g. ZipFile in the snippet), triggers some sort of scan or indexing from pylance that brings the CPU to ~60-70% for long time and VScode becomes unresponsive. Not sure if it's Windows Defender badly interacting with PyLance and VSCode, but...

https://user-images.githubusercontent.com/8077364/202765071-7a3c2139-f48a-4bbe-9011-40719c44985a.mp4

Logs

XXX
erictraut commented 2 years ago

Thanks for the bug report. The code sample above is incomplete and references symbols that are defined or imported from elsewhere. Could you provide a minimal, self-contained code sample that exhibits the problem?

rdbisme commented 2 years ago

Hello @erictraut, unfortunately this is triggered randomly when clicking on some stdlib object to inspect it. E.g. it can be triggered from the following snippet:

from zipfile import ZipFile

than clicking with the right mouse button on ZipFile > Go to Definition.

Or also hovering the mouse on some methods of ZipFile

The problem is, if I close VScode and open it again. It won't trigger again (I guess because the typesheds for the specific module / class have been already processed). But then it will trigger again on some other stdlib object. It seems something related to populating cache or indexes.

rdbisme commented 2 years ago

This is very relatable: https://github.com/microsoft/pylance-release/issues/3632

rdbisme commented 2 years ago

I managed to turn Trace on while it's happening: 9-Python Language Server.zip

rdbisme commented 2 years ago

Another way of triggering it: create a new virtualenv. Switch a Jupyter Kernel to it. That will trigger the scan of all the others virtualenvs (that can be huge)

ooliver1 commented 2 years ago

May be related to #3554

rdbisme commented 2 years ago

Hello, still experiencing this problem. VScode becomes unresponsive and it's basically unusable. Anything I can do to help more?

bschnurr commented 2 years ago

can you upload a file with the trace logs? see https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue

rdbisme commented 2 years ago

@bschnurr Like this: https://github.com/microsoft/pylance-release/issues/3650#issuecomment-1320354310 or something different?

rdbisme commented 2 years ago

@judej I don't understand the "waiting for user response" tag. I replied to @bschnurr and I provided a file with trace logs in https://github.com/microsoft/pylance-release/issues/3650#issuecomment-1320354310. What am I missing?

rdbisme commented 2 years ago

pylance.log.gz

Here's another one while it's happening. Basically PyLance is scanning the entire universe for some reason. And Vscode is unusable.

I'm disabling PyLance for the moment since it makes basically impossible to work with VScode

rdbisme commented 2 years ago

pylance2.log.gz

rdbisme commented 2 years ago

Just as a note, I left the scanning process going all night long and at the morning some apps (e.g. another VScode window) crashed for OOM.

rchiodo commented 1 year ago

The weird part in that last log is this repeated over and over.

(3276) Background analysis message: setFileOpened
(3276) Background analysis message: setFileOpened
(3276) Background analysis message: setFileOpened
(3276) Background analysis message: setFileClosed
(3276) Background analysis message: setFileClosed
(3276) Background analysis message: setFileClosed
(3276) Background analysis message: setFileClosed

I presume this is from running over night?

Can you include your list of other extensions installed and the contents of your user settings.json? Something is closing/opening files?

rchiodo commented 1 year ago

For me, I only get those messages when I open a file.

rdbisme commented 1 year ago

Hello @rchiodo, thanks for the follow up. All those messages start popping up when the CPU spikes and the scan goes on. I get a bunch of them in a matter of minutes once the scan is started.

{
  "workbench.tree.indent": 15,
  "terminal.integrated.profiles.windows": {
    "Git Bash (Scoop)": {
      "path": "C:\\Users\\rdibattista\\scoop\\apps\\git\\current\\bin\\bash.exe",
      "args": ["--login"]
    },
    "UCRT64": {
      "path": "C:\\Users\\rdibattista\\scoop\\apps\\msys2\\current\\usr\\bin\\bash.exe",
      "args": ["--login", "-i"],
      "env": {
        "MSYSTEM": "UCRT64",
        "CHERE_INVOKING": "1",
        "MSYS2_PATH_TYPE": "inherit"
      }
    },

    "MINGW64": {
      "path": "C:\\Users\\rdibattista\\scoop\\apps\\msys2\\current\\usr\\bin\\bash.exe",
      "args": ["--login", "-i"],
      "env": {
        "MSYSTEM": "MINGW64",
        "CHERE_INVOKING": "1",
        "MSYS2_PATH_TYPE": "inherit"
      }
    }
  },
  "workbench.colorTheme": "Solarized Dark+",
  "python.defaultInterpreterPath": "C:\\Users\\rdibattista\\scoop\\shims\\python3",
  "python.venvPath": "C:\\Users\\rdibattista\\AppData\\Local\\pypoetry\\Cache\\virtualenvs",
  "python.formatting.provider": "black",
  "editor.formatOnSave": true,
  "python.sortImports.args": ["--profile", "black"],
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  },
  "python.analysis.logLevel": "Error",
  "terminal.integrated.defaultProfile.windows": "UCRT64",
  "editor.rulers": [80, 120],
  "vim.useSystemClipboard": true,
  "diffEditor.ignoreTrimWhitespace": false,
  "editor.fontFamily": "MesloLGM NF, Consolas, 'Courier New', monospace, 'Segoe UI Emoji'",
  "rust-client.rustupPath": "C:\\Users\\rdibattista\\scoop\\persist\\rustup\\.cargo\\bin\\rustup.exe",
  "security.workspace.trust.untrustedFiles": "open",
  "jupyter.askForKernelRestart": false,
  "terminal.integrated.fontFamily": "MesloLGM NF",
  "gitlab.instanceUrl": "https://gitlab.aws.qrt.cloud",
  "terminal.integrated.fontWeightBold": "bold",
  "editor.fontSize": 13,
  "explorer.confirmDelete": false,
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "vim.neovimConfigPath": "C:\\Users\\rdibattista\\scoop\\shims\\nvim",
  "vim.enableNeovim": true,
  "redhat.telemetry.enabled": true,
  "workbench.editorAssociations": {
    "git-rebase-todo": "default"
  },
  "window.zoomLevel": -1,
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "notebook.output.textLineLimit": 150
}

List of extensions

adamvoss.vscode-languagetool
BazelBuild.vscode-bazel
bungcip.better-toml
cstrap.python-snippets
eamodio.gitlens
esbenp.prettier-vscode
ExecutableBookProject.myst-highlight
genuitecllc.codetogether
GitLab.gitlab-workflow
guyskk.language-cython
mechatroner.rainbow-csv
mhutchie.git-graph
ms-azuretools.vscode-docker
ms-python.isort
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-toolsai.vscode-jupyter-cell-tags
ms-toolsai.vscode-jupyter-slideshow
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode.cpptools
ms-vscode.remote-explorer
rust-lang.rust-analyzer
ryanolsonx.solarized
samuelcolvin.jinjahtml
trond-snekvik.simple-rst
twxs.cmake
valentjn.vscode-ltex
vscodevim.vim
rchiodo commented 1 year ago

Can you try installing the insiders build of VS code and just install the python and pylance extensions into it? And then see if the CPU spikes on that process.

My guess is one of your other extensions is doing something that's closing and opening files.

judej commented 1 year ago

Closing old issue. If this is still a problem, please reopen with the information requested. thanks

rdbisme commented 1 year ago

Just for reference, I recreated a new workspace from scratch, on the same vscode (not insiders), and the problem vanished.