2

I am following this on how to run VSC in WSL environment.

I am able to open my project in VSC in WSL env.

But I see that almost every command is painstakingly slow. For eg., when I run 'git status', it is indexing every time which slows down things a lot.

Do I need to live with it or am I doing things wrong? If yes, I am not sure if using WSL for development is a viable option.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 1
    Not slow for me. How can I reproduce your issue? – Wyck Apr 29 '23 at 04:01
  • Maybe you can try to open some git repository, and run 'git status'. – Mandroid Apr 29 '23 at 04:02
  • 1
    In general, it shouldn't be "slow". SUGGESTIONS: 1) Run a few Linux commands (`ls`, `top`, `cat somefile`, etc.) from a terminal window. See if *they're* "slow". 2) "cd" to your project directory, and run `git status` from the Linux command line. Is it any "slower" than running "git status" inside VSCode? 3) Your VSCode is installed on WSL (not Windows per se), correct? And they're both on a hard drive (or better, an SSD drive), and *NOT* on media like an external USB drive, correct? – paulsm4 Apr 29 '23 at 04:10
  • Just to be clear, I want to confirm, because your wording concerns me. You should not _"run VSC in wsl environment"_ but rather, as the instructions say, you should _Install Visual Studio Code on the Windows side (not in WSL)._ – Wyck Apr 29 '23 at 04:12
  • @Wyck, yes, VSC is installed in windows. Sorry for the confusion. – Mandroid Apr 29 '23 at 04:17
  • @paulsm4, as the isntruction say VSC is installed in windows. – Mandroid Apr 29 '23 at 04:17
  • 1
    Did you do the checks suggested by paulsm4 ? – Philippe Apr 29 '23 at 07:25

1 Answers1

7

The most common cause of performance issues in WSL2 is when attempting to access files on the Windows drive (e.g. through /mnt/c/...). If the project you are working with is on the Windows drive, that would most likely explain the root issue. See my answer to, Why is WSL extremely slow when compared with native Windows NPM/Yarn processing? for details.

As one example from that post, Git actions on the Windows drive when running through WSL2 can take nearly two orders of magnitude longer than when on the Ext4 filesystem. The "normal" hit to performance from running on the Ext4 filesystem under WSL2 varies depending on the type of files being access, but typically runs between 10-50%. For day-to-day development use, you really shouldn't "notice" it. "Painstakingly slow" sounds like the "Windows drive" issue.

However, I'm not totally convinced this is the problem in your case. You mentioned you were able to open your project through VSCode (presumably through WSL), and it should have displayed a warning toast about the performance when you/if you opened a project on a Windows drive. It's possible that you missed it, of course, or possibly habitually clicked-to-dismiss (we all do!).

VSCode can operate in two different "modes" when it comes to WSL:

  • "Windows" (normal) mode
  • "WSL" (extension/remote) mode

Assuming you have the WSL extension installed, VSCode will detect when you started it under WSL and automatically switch to Remote mode. It will also automatically switch into Remote when re-opening a project that was originally Remote.

The general rule is:

  • Open projects in normal/Windows mode when using Windows tools. Store these projects on a Windows drive.
  • Open projects in WSL/Remote mode when you are using Linux tools (processes, filesystems, etc.). Store these projects in the virtual SDD Ext4 filesystem that WSL2 provides (e.g., under your Linux $HOME directory).

You can tell which mode you are in in VSCode by looking at the bottom left corner of the VSCode window. There is a toolbar option on the far left that looks like ><, slightly offset. If you are in "Normal" mode, it will simply be the ><. If you are running under WSL, you'll see the name of the WLS distribution there as well. Hovering will provide more detail.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70