microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.67k stars 292 forks source link

High CPU usage in Remote Desktop process with WSL2 + Ubuntu #9679

Open ACERposS opened 8 months ago

ACERposS commented 8 months ago

I am getting high CPU usage and an unresponsive 'explorer' sidebar in VSCode in a project with somewhat deeply nested directories (React, not Java ;). The 'loading' animation at the top of the sidebar frequently displays, and some files & directories fail to open at all.

Possibly relevant detail: my workstation is managed by a domain administrator and has Windows Defender Smartscreen enabled and locked.

At the times in which the explorer hangs (mostly when renaming, copying or creating files through the explorer) I also see high CPU usage for the Remote Desktop process on my machine but no significant activity from any Nodejs process within WSL:

image

aeschli commented 8 months ago

Likly not an issue in the explorer, but that's where I would start to profile.

The deep tree can cause a lot of file change events. Try excluding some files with the files.exclude and watcher.exclude setting. E.g. for JavaScipt we exclude the node_modules folder

ACERposS commented 8 months ago

Yeah, I don't think it's anything within VSCode itself since I don't see high CPU usage in any node processes within WSL.

I can also confirm it's not related to open file handles (I have had this before but solved it). What I have is on the order of hundreds, not tens-of-thousands:

$ lsof | awk '{ print $1 " " $2; }' | sort -rn | uniq -c | sort -rn | head -15

    552 node 837555
    468 node 837278
    462 node 837212
    238 node 837599
    210 node 837234
    210 node 837225
     72 snapd 680670
     53 systemd 391
     24 python3.1 327

The first of these processes watching 552 files appears to be the extension host process, which is what I'd expect with a project running TypeScript intellisense & ESLint:

$HOME/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node --dns-result-order=ipv4first $HOME/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/out/bootstrap-fork --type=extensionHost --transformURIs --useHostProxy=true
ACERposS commented 7 months ago

Some additional information on this: I routinely receive this popup upon opening any WSL-connected application for the first time after a reboot. It must be dismissed 11 times to silence the warning.

Screenshot 2024-03-22 143801

I have found on some occasions when my machine was essentially unresponsive that this popup was a symptom. I have seen it silently open in the background hundreds of times (perhaps once for each watched file handle?). There appears to be some correlation between the number of popups and the severity of the filesystem performance impact.

aeschli commented 7 months ago

How is Remote Desktop involved here? What I understood: You use Remove Desktop to connect to a Windows Machine that has WSL installed. On that Windows machine you run VS Code (under Window) with the WSL extension to work in WSL.

ACERposS commented 7 months ago

No. I don't (consciously) use Remote Desktop at all. It seems as though its process interferes with a default WSL2 configuration somehow.

All the processes in question are those I'm observing on my own local machine.

stefanbischof commented 6 months ago

Sorry to chime in here. I have a very similar issue on my machine. I have Docker configured to use WSL. A while after starting docker the "Remote Desktop" starts and consumes ~10% cpu. When I terminate the "Remote Desktop" in the task manager, it starts up again. Only when I shutdown wsl (and thereby kill Docker) I can then terminate "Remote Desktop" and it doesn't start again.

Sometimes I have several instances of Remote Desktop running. Although I think this is related to me using remote connections in VS Code. I think the same happens when I use dev containers. In these two cases it somehow makes sense that the "Remote Desktop" process shows up. But for Docker + WSL alone, I find it weird.