prezto icon indicating copy to clipboard operation
prezto copied to clipboard

Slow tab completion on WSL2

Open Fryguy opened this issue 4 years ago • 12 comments

Description

In WSL2, tab completion is very slow on executable files and in certain directories

Steps to Reproduce

a<tab>
# Wait 5-10 seconds and it will eventually show the completion menu

The issue is much more evident when tab completing a specific file that is in the immediate directory and thus doesn't require the menu to appear:

cd ~
touch foo
chmod +x foo
./fo<tab>
# Wait 5-10 seconds and it will eventually complete the word foo

I'm not sure if this is a zsh issue or a prezto issue, however if I disable prezto and use vanilla zsh, the tab completion is instant. The vanilla tab completion doesn't use the menu however, so it could also be the menu's fault, but I'm not sure how to verify that.


I have noticed that WSL, by default, puts a lot of /mnt/c directories (such as /mnt/c/Windows/) on $PATH.

~ ❯❯❯ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/local/sbin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/WINDOWS/system32
/mnt/c/WINDOWS
/mnt/c/WINDOWS/System32/Wbem
/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/
/mnt/c/WINDOWS/System32/OpenSSH/
/mnt/c/Users/Fryguy/AppData/Local/Microsoft/WindowsApps

If I remove those directories, then tab completion is fast. For now, as a workaround I have the following in my profile which works:

export PATH=$(echo $PATH | tr ':' '\n' | grep -v "/mnt/c/" | tr '\n' ':')

With that workaround in place, everything is fast, however I can kind of force the issue anyway by doing:

cd /mnt/c/Windows/System32
a<tab>
# Wait 3-5 seconds for the completion menu to appear

My guess is something about these Windows directories is overloading completion, but I have no idea how to narrow this down any further.

I've also tried the following to no effect:

  • sudo updatedb
  • rm -rf ~/.zcompdump*

Versions

  • Prezto commit: de7b3b7fdc99f8a67320dc64085dea44914969c7
  • ZSH version: zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
  • OS information: Ubuntu 18.04.4 LTS \n \l on WSL2 - Microsoft Windows [Version 10.0.19592.1001]

Fryguy avatar Apr 09 '20 03:04 Fryguy

Faced the same issue here as well. completion gathers some windows specific "exe" binary as well. Basically WSL2 has windows path as well, and that where it get really slow.

dhruvinsh avatar Jul 24 '20 13:07 dhruvinsh

Disable windows paths with appendWindowsPath in wsl.conf: https://devblogs.microsoft.com/commandline/automatically-configuring-wsl/

Then just make aliases to the stuff you use from windows (explorer.exe, vscode etc.)

thor85 avatar Sep 10 '20 10:09 thor85

the completion for directory navigation when using autocd is very slow too

LuanVSO avatar May 23 '21 18:05 LuanVSO

unsetting this option on zshrc will fix it

unsetopt PATH_DIRS

LuanVSO avatar May 23 '21 18:05 LuanVSO

i think this happens because /bin/X11/ is a symbolic link to /bin/ thus creating a circular directory tree that zsh tries to search

LuanVSO avatar Jun 02 '21 22:06 LuanVSO

this still works in April 2022 👍

vinamelody avatar Apr 11 '22 03:04 vinamelody

This in my /etc/wsl.conf fixed the issue for me (PATH crowded with Windows binaries)

[interop]
appendWindowsPath = false

Restart to enable the changes.

lied avatar Oct 02 '22 13:10 lied

@lied If you do that, you won't be able to invoke standard Windows binaries. For many (myself included) this would be a deal breaker.

romkatv avatar Oct 02 '22 13:10 romkatv

i think this happens because /bin/X11/ is a symbolic link to /bin/ thus creating a circular directory tree that zsh tries to search

No, it's because of path_dirs. This is an esoteric option that the vast majority of users don't need.

romkatv avatar Oct 02 '22 13:10 romkatv

This is really a problem with WSL2 -- searching through all the directories in $PATH that are present on the Windows side is just extremely slow, unfortunately. See https://github.com/microsoft/WSL/issues/4197

This really isn't a prezto issue at all, is it? How long does rehash take?

hut8 avatar Feb 26 '23 20:02 hut8

This really isn't a prezto issue at all, is it?

Prezto enables path_dirs, which the vast majority of users don't need, including those that actually know what this option does. As a side effect, path_dirs makes completions slow if you have slow directories in your PATH, which includes all WSL setups. Enabling path_dirs isn't a good default.

romkatv avatar Feb 26 '23 20:02 romkatv

@romkatv Thanks for telling me about this! I agree that it's not a good default; I've never done that without prefixing it with ./ - In fact, I didn't even know that would be an option.

hut8 avatar Feb 28 '23 06:02 hut8

@lied If you do that, you won't be able to invoke standard Windows binaries. For many (myself included) this would be a deal breaker.

You can still run windows binaries by using an absolute path like /mnt/c/Windows/System32/notepad.exe. My solution is to just symlink the few windows binaries I need into my linux path, which works fine.

lucy avatar Apr 24 '23 23:04 lucy