Skip to content
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 causes a huge CPU load #1388

Closed
barthemius opened this issue Jun 3, 2021 · 7 comments
Closed

Pylance causes a huge CPU load #1388

barthemius opened this issue Jun 3, 2021 · 7 comments
Labels
needs investigation Could be an issue - needs investigation needs stub

Comments

@barthemius
Copy link

Environment data

  • Language Server version: 2021.6.0
  • OS and version: macOS Big Sur 11.4 (20F71)
  • Python version (and distribution if applicable, e.g. Anaconda): Python 3.8.8 x64 Anaconda

Expected behaviour

Pylance swiftly analyses the code and highlights the variables (just like week ago).

Actual behaviour

A process called 'Code Helper (Renderer)' uses >100% of CPU for approx 30-50 seconds. I tracked it by PID and unfortunately Pylance is the culprit, switching to a different language server is a remedy.
About the problem - every little change in the code triggers the whole process again. Variable name colouring update takes like a minute.
This issue might be related to #1368 reported by xmatthias. However there, he described the problem occurring in the big project. Here the file I am working on is a short, merely 50 line python script. Additionally I run on a different OS.

What surprises me the most, using older versions of Pylance didn't work at all. I somehow relate this bug to the recent macOS update, but I don't know if it is relevant.

I guess the description I've given might be a bit vague, as I am not familiar with bug reporting like this. However I will happily answer any questions you might have.

Logs

For convenience, I put the log in the attachment.
pylance_problem.log

@github-actions github-actions bot added the triage label Jun 3, 2021
@judej judej added in backlog needs investigation Could be an issue - needs investigation needs stub labels Jun 3, 2021
@github-actions github-actions bot removed the triage label Jun 3, 2021
@jakebailey
Copy link
Member

It appears as though this is sympy, which has some known performance holes and will need some stubs.

@barthemius
Copy link
Author

It appears as though this is sympy, which has some known performance holes and will need some stubs.

Yup, you're absolutely right! I uninstalled sympy and it works fine right now. Too bad I need sympy for my research... :(

@erictraut
Copy link
Contributor

erictraut commented Jun 3, 2021

As a potential workaround, you could create a dummy type stub for sympy. This approach should eliminate the large CPU usage, but the tradeoff is that you won't get any completion suggestions for sympy.

To do this, create a file in your project called typings/sympy/__init__.pyi. Within that file, paste the following:

from typing import Any

def __getattr__(name: str) -> Any: ...

This will tell pylance that it shouldn't attempt to infer any type information from the sympy library.

@barthemius
Copy link
Author

That should do the trick, at least for now. Thank you Eric!

@jakebailey
Copy link
Member

Dupe of #1388.

@mjpieters
Copy link

@jakebailey you closed this as a duplicate of itself, did you mean to do that? Looking at the history, I think you meant to reference #946 instead?

@jakebailey
Copy link
Member

Yes, my mistake! Copy paste always gets me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation Could be an issue - needs investigation needs stub
Projects
None yet
Development

No branches or pull requests

5 participants