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

Extension causes high cpu load #24737

Open
intellegenstom opened this issue Jan 22, 2025 · 15 comments
Open

Extension causes high cpu load #24737

intellegenstom opened this issue Jan 22, 2025 · 15 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@intellegenstom
Copy link

  • Issue Type: Performance
  • Extension Name: python
  • Extension Version: 2024.22.1
  • OS Version: Windows_NT x64 10.0.22631
  • VS Code version: 1.96.4

ms-python.python-unresponsive.cpuprofile.txt

Find more details here: https://github.com/microsoft/vscode/wiki/Explain-extension-causes-high-cpu-load

@intellegenstom
Copy link
Author

Profile looks like this (time on the right is hanging):

Image

@karthiknadig
Copy link
Member

@intellegenstom Was this during a diff with python code in it?

@intellegenstom
Copy link
Author

I had the vscode source control panel open, but was not actively looking at a diff. I was working on a large python codebase

@karthiknadig
Copy link
Member

What do you have for the python.languageServer setting?

@intellegenstom
Copy link
Author

Pylance. I'm also getting the freezes with the source control panel closed now I check this

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Jan 22, 2025
@rchiodo
Copy link

rchiodo commented Jan 22, 2025

@karthiknadig the cpu profile here is for the python extension, this wouldn't be actionable by Pylance.

@intellegenstom is there a cpu profile for the pylance extension?

@rchiodo
Copy link

rchiodo commented Jan 22, 2025

Additionally, pylance has some commands you can run if you think it's the cause of a slowdown. Generally, a freeze in the UI isn't Pylance though as we run most of our code in a separate process.

@karthiknadig
Copy link
Member

This might be an issue with the diff-editor. In the python extension we really don't specifically look at diffs.

The uploaded CPU profile and the one in the image you have shared seem very different. The CPU profile in the screen shot is for the workbench process, and the extension profile is from extension host process.

@intellegenstom
Copy link
Author

I'm not an expert in debugging vscode behaviour, @rchiodo could you let me know how to generate a profile for a specific extension - I just used general performance monitoring from the developer tools. The freezes seen at the same time as the cpu profile file and at the same time as the performance profile screenshot were qualitatively similar, but I don't know if that means they are caused by the same issue

@rchiodo
Copy link

rchiodo commented Jan 23, 2025

You can profile an extension in VS code through the 'Show Running Extensions' command. Then you right click on the extension you think is the problem and click 'Start Extension Host Profile'

Image

What you did was profile the whole application (using Developer tools), which is probably where the problem is given that a big chunk of time was in the diff editor. But if you profile the Pylance extension we can see if there's any time spent there.

You stop the extension profile with a right click again:

Image

Then that should show how much time was spent in each extension. You right click again to save the profile and upload it:

Image

@intellegenstom
Copy link
Author

I'm not quite sure how to read this, but it looks like the Python extension is the one being highlighted?

CPU-20250123T164455.064Z.cpuprofile.txt

Image

@rchiodo
Copy link

rchiodo commented Jan 23, 2025

Yeah at least the profile shows 1.5 seconds in the Python extension. Transferring back to Python.

@rchiodo rchiodo transferred this issue from microsoft/pylance-release Jan 23, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 23, 2025
@karthiknadig
Copy link
Member

@eleanorjboyd Looks like the time here is being spent on creating test items for the test explorer.

@intellegenstom We have auto re-discover tests on by default. It looks like in this case it is causing a lot of load attempting to create items. You can turn it off as a workaround.

@eleanorjboyd
Copy link
Member

@intellegenstom does it work to lower load if you turn off the auto-discovery on save? Could you give me a sense of the test suite as well? Approx how many tests does it have? does it use pytest or unittest? Does it have plugins or use subtests/parameterized tests? Does it have large amount of nesting / folders or is it relatively flat? These can give me a sense of what about this project is making it so costly for CPU and where I can look for a fix

@eleanorjboyd eleanorjboyd added area-testing info-needed Issue requires more information from poster bug Issue identified by VS Code Team member as probable bug labels Jan 24, 2025
@intellegenstom
Copy link
Author

Thanks - I turned off "python.testing.autoTestDiscoverOnSaveEnabled": false and after restarting all vscode windows it does seem to be running smoother. This repository does have several tests (pytest - probably around 100 test files total in five or six folders, all several layers deep in folder nesting, all using pytest.param fairly heavily) but I wasn't actively developing on these - the test files were all closed when getting freezes.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

5 participants