-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syntax highlighting is super slow in WSL2 #790
Comments
What are the version numbers of zsh and zsh-syntax-highlighting in each environment? |
@danielshahaf I'm on zsh 5.8 and the latest version of zsh syntax highlighting installed via git clone. I'm using Ubuntu-20,04 via WSL2 |
@danielshahaf <https://github.com/danielshahaf> I'm on zsh 5.8 and the
latest version of zsh syntax highlighting installed via git clone. I'm
using Ubuntu-20,04 via WSL2
What are the version numbers on the WSL1 environment?
Assuming everything is the same except WSL1 v. WSL2… well, I don't know of any developers who use WSL (either version), so you may have to debug this yourself. Getting a minimal reproducer (one that doesn't even involve z-sy-h, if possible), and/or employing `zprof`/`set -x` to identify the slow part, would be reasonable starting points.
|
encounter the same issue |
To answer the deleted comment: z-sy-h uses $PATH via the That can be ruled out simply by trying to reproduce the issue under |
I noticed some sluggish behaviour while on WSL2 but nothing like a 1 second delay (if I had to guess about ~200ms). ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/c) This makes the "cold" highlighting after a fresh start a bit faster. Surprisingly enough it still recognizes commands like |
Adding Is there anything else to try? |
(I just posted that on #899, but it works equally well as an answer to @wywywywy.) |
I solved this by excluding windows directories from
Then restart wsl with
It's also possible to disable the possibility to run windows binaries inside WSL instances with the following in
|
For my use case I still want some Windows paths. For example the |
You could make some aliases for your common windows commands if you still wanted to exclude the windows directories from the $PATH. For example |
I ended up manually adding that bin to
I wonder which windows paths causes the poor performance of syntax highlighting. |
I imagine it's not any specific paths that causes the slowdown, it's probably just the number of paths. |
@amimof Thanks for the info that removing some entries from $path resolves the slowness. First, I'd like to check whether there are any other causes of slowness at play here. So:
|
WSL2 is well known to have poor performance interacting with Windows' filesystem. There's an open issue dating back to 2019: microsoft/WSL#4197 Workarounds include working inside WSL2's filesystem or creating an NFS server and use that instead (which funnily enough, seems to work faster than the native WSL2's way of doing it). This performance issue directly affects anything that has to do with Windows' path, to list a couple:
This workaround "solves" the problem. By removing Window's paths from WSL2 we won't take the performance hit of doing lookups outside Linux... but we lose a bit of the cool integration with Windows. Using From what I can gather, the So added this # .zshrc
### Windows ###
export PATH="$PATH:/mnt/c/Users/lesmo/AppData/Local/Microsoft/WindowsApps"
export PATH="$PATH:/mnt/c/Users/lesmo/AppData/Local/Programs/Microsoft VS Code/bin"
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin"
export PATH="$PATH:/mnt/c/ProgramData/DockerDesktop/version-bin"
export PATH="$PATH:/mnt/c/WINDOWS" Maybe we just need to figure out why |
Sinuhé Coronel wrote on Mon, 23 Jan 2023 07:22 +00:00:
So added this `appendWindowsPath` flag and re-added some of my Windows'
paths to my `.zshrc` (including the Windows folder itself), and the
slowness is gone for me (these are most likely what the average coder
using WSL2 will need anyway):
```sh
# .zshrc
### Windows ###
export PATH="$PATH:/mnt/c/Users/lesmo/AppData/Local/Microsoft/WindowsApps"
export PATH="$PATH:/mnt/c/Users/lesmo/AppData/Local/Programs/Microsoft VS Code/bin"
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin"
export PATH="$PATH:/mnt/c/ProgramData/DockerDesktop/version-bin"
export PATH="$PATH:/mnt/c/WINDOWS"
This might be more readable with the array counterpart of $PATH:
```zsh
path+=(
/mnt/c/Users/lesmo/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/lesmo/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Program Files/Docker/Docker/resources/bin
/mnt/c/ProgramData/DockerDesktop/version-bin
/mnt/c/WINDOWS
)
```
```
Maybe we just need to figure out why `ZSH_HIGHLIGHT_DIRS_BLACKLIST`
doesn't seem to work?
ZSH_HIGHLIGHT_DIRS_BLACKLIST only applies to words literally typed on
the command line. It doesn't magically cause $PATH directories not to
be hashed. That's actually a zsh functionality, not a z-sy-h one. So, perhaps this:
```zsh
() {
set -- $path # save $PATH without overwriting any user variables
path=( /some /directories /that /can /be /stat\(2\)ed /performantly )
rehash
path=( "$@" )
}
```
With this, commands from other directories will only be runnable by
their full paths, or after running `rehash` again.
May need to add an 'always' block, depending on how exactly the
temporary value of $PATH is computed.
|
@amimof Thanks, that's useful for me. |
marked, helped me as well |
same problem here, but I still want to keep windows path in WSL2, because I often use windows commands like maybe there's a bug of |
Thank you @amimof, it worked for me. |
Thank you! That helps a lot! |
Thank you @amimof, It's propery worked fine |
Thank you @amimof, It's worked perfectly. |
Thank you @amimof! |
On WSL the zsh syntax highlighting worked perfectly, but in WSL2 it's extremely slow. When you type there's about a 1 second delay before your input is actually shown. Not sure if it's a problem with WSL2 or the highlighting itself.
The text was updated successfully, but these errors were encountered: