-
Notifications
You must be signed in to change notification settings - Fork 769
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
Pylance is using over 100% CPU. #201
Comments
Thanks for the bug report. A few follow-up questions:
Pylance already contains an in-memory caching mechanism, but it eventually needs to empty the cache if it exceeds ~1GB in size to avoid overflowing the heap. If you're analyzing all of the code in a very large code base, it can exceed this level. |
Thank you for your prompt response!
Yes, I have one file open. It won't occur if I don't have any python file open. It doesn't matter which one or how many. When I was printing the log, one random file is open, which has around 100 lines of code.
If I close all files, the logs still keep printing. It can get triggered by any open file.
No, I'm not editing. I just opened a random file for the purpose of bug-reporting.
I don't see any spinner in the status bar. Only the output window is indicating that Pylance is analyzing.
Previously I don't have
The size of my virtual env is around 2GB. Plus, is there any on-disk caching, so that it doesn't run all the analysis again after I close and re-open Vs Code? |
Thanks for the additional details — much appreciated! This is a problem we haven't seen before, so I'm very interested in getting to the bottom of it. Based on the symptoms you're describing, I can conclude the following:
By any chance, is your project open-source (e.g. available on github)? If so, I could try to repro the problem locally. If not, I'll need to ask you to help me narrow down the problem. Here's what I recommend as the next steps. Create a temporary "temp.py" file somewhere in your source base. Leave it empty for now. Close all files except for this one, then close and re-open VS Code. See if the problem occurs. I predict that it won't. Next, open another source file — one that triggers the high CPU utilization. Copy its contents into temp.py. Delete all of the code except for the imports at the top. Close all of the files except for temp.py, and repeat the experiment. If it triggers the problem, binary search the list of imports (i.e. delete half of them) and repeat until you find the import that causes the problem. If you don't see the problem with only the imports, then try binary searching the code beneath the imports (i.e. add back half of the classes/functions/methods and see if that causes the problem to re-appear). |
Thank you! I'm trying to track it down as well. Interesting problem.
Wow, man, your deduction is precise! I have checked out a remote library and installed it as an egg in my workspace! And I'm importing that library from almost any file. Unfortunately, the project is not open source. I tried to create a minimal demo to reproduce the same problem but still in the working process. Anyway, my problem is likely caused by the egg installed in my local workspace. I'll move it away, and I believe that will solve my problem. Thank you again for all your help. And I think this is not a Pylance issue. Sorry for the false alarm. |
OK, that's a great find. I still suspect this might be a bug in Pylance. It shouldn't get into a situation where it's using >100% CPU for long stretches of time. There must be something about that code (e.g. a difficult control flow construct) that it's struggling to analyze. By any chance, is the remote library you installed available as open source? If so, I could try to replicate what you did. |
By default we should be detecting virtual environments and ignoring them. You censored the folder structure, which makes it difficult to understand what the problem could be with this detection. |
i can reproduce the behavior with the following steps. Requirements:
trink a coffee, it takes a while! for a test create an stupid empty addon:
awnser all question that you see and use the default values as example open in VSCode src/myaddon.test/src/myaddon/test/interfaces.py with an activated pylance extension CPU is near by 100% and the RAM usage goes up? thats my settings.json |
I am experiencing the same issues with the latest Python &Pylance plugin without virutal env. |
with this settings in a testproject i have no problems:
|
The high CPU utilization is caused by a new indexer that was added in the latest release of Pylance. It runs at startup and indexes all of your site-packages and workspace files so it can support auto-import. We're looking at ways to improve it so it doesn't consume so many resources. |
I have noticed the Pylance - autocomplete along the Python Extension is taking very long time to start once Vs Code is launched since the versions pushed since August 2020 |
I've got the same issue on a machine with a Plone installation. 5 or 6 threads are running the command |
Pylance doesn't run ripgrep; VS Code's search I believe does, but I know for certain the only external tool we run is Python itself. It must be another extension or the editor itself. This thread was mainly about a new indexer, which is currently disabled in Pylance (and being improved before we enable it again). |
Okay, but why did it stop to consume IO resources as soon as I downgraded Pylance to a version before August? I did not change anything else. |
@NicolasGoeddel Are you still experiencing this on the latest (2020.10.2)? We've made some perf fixes in the last couple releases. |
I have the same issue in the latest version of Vscode e Pylance. |
@vnikoofard would you be able to enable trace logging and share the output with us? This would help our team investigate what might the issue might be. |
Even without any open tab the CPU usage is over than 100%. In the [Info - 10:41:53 PM] Pylance language server 2020.11.1 (pyright 54be42d2) starting |
The type analyzer is struggling with the file "tmp/tmp-820420dimj9i0GFrJ.py". It's taking 517s to complete the analysis for this module. From the name, I'm guessing that this is an auto-generated file? There must be something within it that's exercising an algorithm within the type checker that does not scale well. Could you look at that file and see if anything is obviously atypical? |
@erictraut I couldn't find the mentioned file in the
The strange point is that this file is empty (0 bytes)! Closing VSCode the file disappeared. |
Maybe some kind of race condition where the mentioned file got created, written to, modified and so on. Maybe it also should be deleted again but Pylance has locked it because it was just parsing it? |
That wouldn't explain it. To be clear, this file isn't created by — or deleted by — pylance. I don't know who is generating it, but it must have some large, complex python code in it at some point. Pylance reads the contents of a file from start to finish in one synchronous call and performs all parsing and analysis on the in-memory copy of the file contents. |
Experiencing the same. |
This issue dates back months, and the previous conversation was a month ago (a few releases ago). It's unlikely that that you're experiencing the same issue as others here. We'd appreciate a new issue with the template filled out so we can get trace info. The original issue was about the indexer, which I believe has been fixed for a while. The more recent followups appear to be about a different issue relating to a tempfile; if this is still a problem in recent releases we can open a new issue to try and track it. I'm going to close this; in general it's not a good idea to have a single issue for "it's using a lot of CPU" as each individual case can differ significantly. This likely should have been closed once the indexer was disabled. |
Thank you Jake. Yes this issue was resolved for while now. Not sure about
anything new now. Regards Tridib
…On Tue, Dec 15, 2020 at 2:16 AM Jake Bailey ***@***.***> wrote:
Closed #201 <#201>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#201 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOT3LVBGYNCADVCEYPXL4ODSUZ2TNANCNFSM4PU364UQ>
.
|
Hi there, I still can confirm that PyLance uses 100% CPU. I'm working on Ubuntu 18.04 with VSCode 1.59 installed:
Whenever PyLance is enabled and I open a bigger Python program, it eats up 100% of the CPU and after a while the fan starts continuously running. Disabled PyLance and switched to Jedi and the problem has gone. Regards, Thomas |
@mosesontheweb, it sounds like you're encountering a different issue. We'd appreciate it if you'd file a new bug report and include logs — or even better, if the source base is in a public repo, provide repro steps. Thanks! |
Hi, Also suffering from high CPU usage from Pylance under VS Code. Any modification to a Python source file causes high CPU usage (~50 % in all cores) for ~3 mins, with syntax coloring being equally slow. I've traced it to the change from version 2021.8.1 of Pylance (that works OK) to 2021.8.2 and up (that show the issue). From VS Code - About: Thanks & regards. |
hey !! me too !! exact same problem !! It started yesterday for me ! It seems the problem will be fixed very soon |
Issue seems to remain until this day. Had to disable pylance since it turns my laptop into an oven VS: 1.72.1 |
Yes it does, it was fixed during a long time and since around two weeks the issue came back again. I Fixed it by switching to the unstable version of Pylance |
is it a public code repo? |
No, but I can give you access. |
Same issue on win10 |
@DanielHabenicht I'm experiencing a similar issue on Codespace. Everything works fine until the CPU usage surges and then the Remote Extension crashes. Did you find out a solution? |
same here, pylance is a constant drain on my machine |
@whateverforever. please log a new issue ideally with a code example. |
@bschnurr I've one issue to fulfill the requirement of |
You should see |
We have the same issue, although I'm only experiencing this if Codespace disconnects due to inactivity. If I leave vscode open after it disconnects, my laptops turns into an oven. I'm still looking for a solution. |
I stopped using Codespaces with pylance. Locally I have a beefy enough machine. |
When I use jupyter in VScode with the .ipynb extension and create 8 small windows to run different programs at the same time, pyalce always does file analysis and says there are 8 files being analyzed, the CPU is high. I waited for the analysis to finish, but as soon as I moved the keyboard cursor, there were 8 files that started to be analyzed, and as the window increased to 13, my computer was about to burn. However, I switched to a 6-month-old, or 5-month-old, pyalce version, and the problem was solved, but I wanted to use the new one. |
@Hong-DaShan, if you are still seeing this on recent Pylance builds, could you please open a new issue with repro steps? Providing your code and the packages that your code is using may also help us reproduce this issue on our side. |
Environment data
2020.7.4 (pyright a65343ef)
MacOS 10.15.6
pyenv virtual env, 3.7.6.
Expected behaviour
Using 10% - 30% of CPU. Or use 100% for a little while then reduce CPU usage to around 20%.
Actual behaviour
Always using over 100% of CPU.
How to reproduce
Open Vscode Process Explorer, a process named
electron_node bundle.js
is using around 110% CPU.Disable Pylance, then reload. The above process disappeared, and Vscode cpu usage drops to around 10%.
Enable Pylance, then reload.
electron_node bundle.js
appears again and is using around 110% CPU.Logs
A small chunk of the logs:
10 minutes later
Not that
binding: .../fastapi/__init__.py (0ms)
appeared at least twice.It keeps logging for around 20 minutes and it's not stopping. Indeed I have a huge amount of dependencies, but is there a caching mechanism I can enable so that it doesn't always use 100% of CPU?
Code Snippet / Additional information
No code involved.
XXX
The text was updated successfully, but these errors were encountered: