microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Opening many editors cripples my machine #9798

Open abyrd-phx opened 2 years ago

abyrd-phx commented 2 years ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: When opening many editors the extension spins up so many Intellisense processes my PC becomes unresponsive and unusable until I kill them manually or close VSCode. These processes linger even after closing editors.

Steps to reproduce:

  1. Open many editors (10-30)
  2. Notice the number of Intellisense processes running in the background and the resulting CPU usage
  3. Close all editors
  4. Notice the Intellisense processes stick around for a long time (possibly until they finish?)

For additional context, this happens in an Unreal Engine codebase (where includes are notoriously heavy and Intellisense has its work cut out for it) while making sweeping refactoring changes. I end up opening 10-20 files at a time, making the same change to each of them, then closing them and starting another batch.

Expected behavior

1) The number of Intellisense processes for unfocused editors is limited to a reasonable number based on the available CPU cores. 2) Intellisense processes are closed immediately when an editor is closed.

Code sample and Logs

.

Screenshots

No response

Additional context

No response

sean-mcmanus commented 2 years ago

The number of IntelliSense processes kept alive defaults to 2 times the number of cores, but you can override that with the C_Cpp.intelliSense.maxCachedProcesses setting. Is that sufficient?

The IntelliSense processes do close after the file is closed, but there is an intentional delay of a few seconds. Our team isn't aware of any bug with the IntelliSense processes not closing so let us know if you have more repro details on that.

FYI, the Unreal Engine code base performance with IntelliSense would be improved by implementing https://github.com/microsoft/vscode-cpptools/issues/3628 , which is what VS implemented: https://devblogs.microsoft.com/cppblog/18x-faster-intellisense-for-unreal-engine-projects-in-visual-studio-2022/

bobbrow commented 2 years ago

The IntelliSense processes do close after the file is closed, but there is an intentional delay of a few seconds.

For more context on this, it is because of the way go to definition/declaration works. The default value for the Workbench > Editor: Enable Preview setting is true. This means that if you go to definition/declaration on a source file that is in a preview editor and the place we're navigating to is in a different file, VS Code "closes" the previewed file and "opens" the new file in the preview editor. This would cause us to shut down and restart the language server for that source file, when in most cases we could continue to reuse the language server. As a result, we added a delay of either a few seconds or a few IntelliSense operations to confirm that we could reuse the language server for the file that got swapped out.

abyrd-phx commented 2 years ago

The number of IntelliSense processes kept alive defaults to 2 times the number of cores, but you can override that with the C_Cpp.intelliSense.maxCachedProcesses setting. Is that sufficient?

It's workable, but not ideal because I'd have set it in every workspace. I sync my settings between computers with different numbers of cores.

The IntelliSense processes do close after the file is closed, but there is an intentional delay of a few seconds. Our team isn't aware of any bug with the IntelliSense processes not closing so let us know if you have more repro details on that.

I'm seeing a delay of 12-13 seconds when opening and closing a single file. I'm not seeing the processes close after multiple minutes when I open and close 38 editors. They appear to be permanently stuck open. I'll see if a smaller repro case is easy to find. I can barely type this message because there are 34 processes open on my 24 thread machine.

we added a delay of either a few seconds or a few IntelliSense operations to confirm that we could reuse the language server for the file that got swapped out

Could this be done by explicitly tracking when an Intellisense process is being kept alive for a specific operation, rather than being done by default? It seems like this leads to somewhat pathological behavior when opening and closing many editors during a noisy refactoring operation.

What happens if I have a 4 thread machine, I open 4 editors, close 1, then open a new one? Will it start a 5th process while the 4th one's shutdown is delayed? Will it avoid opening or delay the 5th process? Or will it preempt the 4th process?

abyrd-phx commented 2 years ago

Intellisense processes exit after 12 seconds when opening and closing 1 editor. Intellisense processes exit after 17 seconds when opening and closing 10 editors. Intellisense processes exit after 153 seconds when opening and closing 20 editors.

Looks like there's something exponential happening.

When opening 20 editors my CPU usage is around 40% and my memory usage is at 100%. This leads to slamming the page file and everything grinding to a near halt.

I'd like to suggest managing the Intellisense processes to avoid massively oversubscribing the system. Perhaps something along these lines:

sean-mcmanus commented 2 years ago
sean-mcmanus commented 2 years ago

Also, the various memory/CPU settings are "machine" scope, so you should only need to set them once per machine and they shouldn't sync to other machines.

On a 4 core machine, there may be a period of time where the number of IntelliSense processes is over the ideal number.