Reducing CPU consumption in VS Code by 5 times [Кратко]

Hello everyone, I recently encountered a problem – my work laptop started making unusual noise from its cooling system. In the task manager I saw the following picture:

There were no other windows open except for the empty project. On StackOverflow, it was suggested to run without extensions and see consumption (identical in my case), disable auto-update of extensions, but these methods did not help me.

At some point I decided to play Jenga – stop the process that was loading the computer and see what would “fall off”

Suddenly – at first glance, nothing: neither the theme crashed, nor the EIDE projects stopped compiling, everything worked normally, even the Cortex-Debuger debugger

But Marketplace doesn’t work

It does not display a list of installed Extensions (they are always in 0) and does not allow you to disable/enable them

But the CPU is loaded at 10 – 12% in idle mode, the coolers themselves stopped working after 30 seconds

But it’s not like a programmer to go into the Task Manager every time, open the process tree, and stop the Marketplace, right?

We need a script that can be added to tasks.json

$vsCodeProcess = Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 1
if($vsCodeProcess.Name -eq "Code")
{
  Stop-Process -Id $vsCodeProcess.Id  -Force
  Write-Host $vsCodeProcess.Name "Successfully stopped"
}
else{
  Write-Host "No Code to stop"
  $secondMostConsumingProcess = Get-Process

At first I expected that VS Code would always be at the top of the sorted list of processes by CPU consumption, but this was not always the case, so I added a check by application name and repeated search

All that remains is to run the script. We add the following to tasks.json, having previously created the file “taskkill.ps1” in the folder in my case

    {
      "label": "Run PowerShell Script",
      "type": "shell",
      "command": "powershell.exe",
      "args": ["-File", "${workspaceFolder}/taskkill.ps1"],
      "group": {
          "kind": "build",
          "isDefault": true
      }
    }

Now that the task has been created, it can be called via Ctrl + Shift + P

Fig 2. Looking for our task

Fig 2. Looking for our task

After pressing “Enter” we find our task and call it

It doesn’t always work the first time, I don’t really understand why yet

It doesn’t always work the first time, I don’t really understand why yet

Attempt number 2:

Results:

Task Manager after script execution

Task Manager after script execution

Task Manager now displays the most CPU-intensive service tasks

Loss of Marketplace

Loss of Marketplace

The Marketplace is not available, but the extensions work (The OneDark Pro theme is not crashed, the project in EIDE is compiled, sewn into the microcontroller and Cortex-Debug works)

Work in progress

Work in progress

Thank you all for reading to the end, please share how you can improve this method, for example, making the script run automatically when you start VS Code, the “onStartup”: “Run PowerShell Script” parameter in tasks.json did not help me

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *