Why is WSL extremely slow when compared with native Windows NPM/Yarn processing?

Since you mention executing the same files (with proper performance) from within Git Bash, I’m going to make an assumption here. Correct me if I’m wrong on this, and I’ll delete the answer and look for another possibility.

This would be explained (and expected) if your files are stored on /mnt/c (a.k.a. C:, or /C under Git Bash) or any other Windows drive, as they would likely need to be to be accessed by Git Bash.

WSL2 uses the 9P protocol to access Windows drives, and it is currently (See Footnote) known to be very slow when compared to:

  • Native NTFS (obviously)
  • The ext4 filesystem on the virtual disk used by WSL2
  • And even the performance of WSL1 with Windows drives

I’ve seen a git clone of a large repo (the WSL2 Linux kernel Github) take 8 minutes on WSL2 on a Windows drive, but only seconds on the root filesystem.

Two possibilities:

  • If possible (and it is for most Node projects), convert your WSL to version 1 with wsl --set-version <distroname> 1. I always recommend making a backup with wsl --export first.

    And since you are making a backup anyway, you may as well just create a copy of the instance by wsl --importing your backup as --version 1 (as the last argument). WSL1 and WSL2 both have their uses, and you may find it helpful to keep both around.

    See this answer for more details on the exact syntax..

  • Or just move the project over to somewhere under the WSL root, such as /home/username/src/.


Footnote:

There may be some hope for improvement in this area based on recent developments. Patches for 9P have been released upstream which are reported to provide a significant performance boost. See this Github thread comment (and the parent thread) for more information.

Leave a Comment