pyright icon indicating copy to clipboard operation
pyright copied to clipboard

high cpu comsumption when pyright enabled

Open vec20 opened this issue 7 years ago • 21 comments

  • pyright version: 1.0.28
  • vscode version: 1.34.0
  • os version: windows 7

CPU % Memory (MB) pid Name 1 124 26596 code main 0 66 20076 shared-process 0 152 20560 window 0 207 23940 window (Running Extensions - Visual Studio Code [Administrator]) 0 109 5740 extensionHost 13 125 23256 electron_node server.js 0 116 25884 gpu-process 0 57 27148 window (Process Explorer)

CPU-20190518T034059.896Z.cpuprofile.txt

vec20 avatar May 18 '19 03:05 vec20

I'll need more information to diagnose what you're seeing.

  1. Does the high CPU consumption continue for a long time (more than 30 sec after opening a project)?
  2. Do you see the progress spinner at the bottom of the VS Code status window? It should show how many files are left to analyze. Does this file count decrease, or does it appear to be "stuck"?
  3. How many python source files are in your project?
  4. If you install and run the command-line version of pyright, you can specify a "--verbose" option which will print detailed timing stats. Installation instructions for the command-line version can be found on the pyright GitHub site. Thanks for the additional information.

erictraut avatar May 18 '19 03:05 erictraut

  1. Yes. CPU's single core starts to run at 100% all day long when I open single .py file, even empty one.
  2. No. 0 1
  3. One.
  4. I tried command-line version. I think the command-line version runs without any problem.

vec20 avatar May 18 '19 04:05 vec20

Thanks for the additional information. This is the first I've heard of this behavior, and I'd like to figure out the cause.

Could you go to the OUTPUT tab and choose the Pyright output view, and see what logged information is shown? It should start with something like "Pyright language server starting".

erictraut avatar May 18 '19 04:05 erictraut

  1. OUTPUT tab: 3
  2. ugh while running some 'problems' appeared. It looks like pyright is processing some files background? The \HashiCorp\Vagrant\embedded\mingw\bin\lib is located at C:\HashiCorp\Vagrant\embedded\mingw\bin\lib. I have never opened that directory/files. I have no idea why the files are being processed... 2

vec20 avatar May 18 '19 04:05 vec20

OUTPUT tab -> pyright log is attahced. output_pyright.txt

vec20 avatar May 18 '19 04:05 vec20

Pyright normally scans for python files anywhere beneath the root directory of your project (the folder you opened in VS Code). I suspect that it's somehow using the root of your drive instead. That would explain the high CPU utilization and why you're seeing errors in files that you don't expect.

This could be Windows-specific behavior. I'll dust off my Windows machine and see if I can repro the problem.

Here's a possible workaround. Try adding a "pyrightconfig.json" file to the root of your project.

erictraut avatar May 18 '19 05:05 erictraut

I added a "pyrightconfig.json" file and it looks like the problem is solved, thanks!

vec20 avatar May 18 '19 05:05 vec20

OK, that's a great clue. I should have enough to repro the problem now.

erictraut avatar May 18 '19 05:05 erictraut

I tried out a few cases (open as folder/single file, or pyrightconfig.json exists/not exists)... I think the problem occurs only when the .py is opened as single file (not as an entry of opened folder), regardless of whether the pyrightconfig.json file exists or not.

vec20 avatar May 18 '19 05:05 vec20

Thanks for the bug report. This is now fixed in 1.0.29, which I just published. If you still see a problem, please re-open the bug.

erictraut avatar May 18 '19 08:05 erictraut

I just experiences the same same issue running with 100% CPU and total lock of nvim in my case. pyright 1.1.189 NVIM v0.6.0-dev+493-g035d82e0d

Workaround with adding an empty pyrightconfig.json worked for me.

kaar avatar Nov 22 '21 12:11 kaar

I have similar problems. @kaar can I ask you about the content of pyrightconfig.json ?

Update:

In the docs there's a sample pyrightconfig.json file.

asdf8601 avatar Dec 16 '21 06:12 asdf8601

I have similar problems. @kaar can I ask you about the content of pyrightconfig.json ?

Update:

In the docs there's a sample pyrightconfig.json file.

I had no content at all. Just put an empty file. I've not ran into the issue in a while now. Had this issue with neovim 0.6 and lsp pyright but has after this also upgraded nvim to 0.7 so no longer sure I can reproduce the issue.

kaar avatar Dec 16 '21 08:12 kaar

Same here, using pyright with neovim LSP. Adding pyrightconfig.json fixes the problem, otherwise I got one core at 100%.

pogopaule avatar Feb 14 '22 15:02 pogopaule

I have 100% CPU. Neovim LSP. Neovim version 0.7.0 build 1319. I have always had a pyrightconfig.json. I can't say if the issue was present before, I just noticed today. Lucky I've got 12 cores. It might be because we've got ~3200 python files in the repo.

Emptying my pyrightconfig.json doesn't reduce CPU usage.

ristillu avatar Mar 25 '22 10:03 ristillu

Emptying my pyrightconfig.json doesn't reduce CPU usage.

To clarify it was the existence of the file that made a difference for me and not its content.

kaar avatar Mar 25 '22 10:03 kaar

Thanks kaar, acknowledged.

ristillu avatar Mar 25 '22 11:03 ristillu

For people using pyright with neovim LSP, setting diagnosticMode = "openFilesOnly" in the server setup solved the issue for me. Of course, that if you just want feedback in open files.

jandvanegas avatar Aug 18 '22 11:08 jandvanegas

Had 100% CPU when opening a file within venvs outside of my project root. Solution: cd $HOME; touch pyrightconfig.json (i.e. an empty pyright config file in the home folder)

axgkl avatar Oct 02 '22 00:10 axgkl

I have 100% CPU. Neovim LSP. Neovim version 0.7.0 build 1319. I have always had a pyrightconfig.json. I can't say if the issue was present before, I just noticed today. Lucky I've got 12 cores. It might be because we've got ~3200 python files in the repo.

Emptying my pyrightconfig.json doesn't reduce CPU usage.

Did you manage to find a fix? I am facing the same issue.

yudhiesh avatar Oct 03 '22 01:10 yudhiesh