Skip to content
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

Windows: Read System32 from PATH in WSL more picky #5309

Open
kesnar opened this issue Mar 23, 2024 · 1 comment
Open

Windows: Read System32 from PATH in WSL more picky #5309

kesnar opened this issue Mar 23, 2024 · 1 comment

Comments

@kesnar
Copy link

kesnar commented Mar 23, 2024

First of all, I have to say that I love the work you have done for xonsh! It is an awesome tool and hope that it gets the recognition it deserves in the future!

So, I am using xonsh in WSL in Windows 11. I have tried both in Debian WSL and Ubuntu WSL, with both the xonsh installed through apt and through pipx.
The problem I face is that there is a big startup time for xonsh of around 2-3 seconds. I searched a bit around and found out that the reason is that the PATH variable in WSL is too long (both in length and in terms of programs) because Windows append the PATH with the Windows PATH.

I was able to stop that from happening, and have normal startup times, by following this microsoft doc: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configure-per-distro-launch-settings-with-wslconf

Bellow in the Showcase section you can see the difference and steps to reproduce it.

So my question is basically if there is another way to handle this, instead of just removing the Windows PATH?
Also maybe this should also be documented somewhere in the docs?

xonfig

kesnar@glotka ~ $ xonsh --timings
 Debug level: Off
|-------------------------|-----------|-----------|
|Event name               | Time (s)  | Delta (s) |
|-------------------------|-----------|-----------|
|start                    |   0.000   |   0.000   |
|pre_execer_init          |   0.004   |   0.004   |
|post_execer_init         |   0.028   |   0.024   |
|pre_xontribs_autoload    |   0.028   |   0.000   |
|post_xontribs_autoload   |   0.036   |   0.008   |
|on_pre_rc                |   0.036   |   0.000   |
|on_post_rc               |   0.087   |   0.051   |
|on_ptk_create            |   0.096   |   0.010   |
|on_post_init             |   0.097   |   0.000   |
|on_pre_cmdloop           |   0.097   |   0.000   |
|on_pre_prompt_format     |   0.097   |   0.000   |
|on_pre_prompt_tokenize   |   0.120   |   0.024   |
|on_post_prompt_tokenize  |   0.126   |   0.005   |
|on_pre_prompt_style      |   0.144   |   0.019   |
|on_post_prompt_style     |   0.146   |   0.001   |
|on_pre_prompt            |   0.146   |   0.000   |
|-------------------------|-----------|-----------|
kesnar@glotka ~ $ xonfig
+------------------+-----------------------+
| xonsh            | 0.13.4                |
| Python           | 3.11.2                |
| PLY              | 3.11                  |
| have readline    | True                  |
| prompt toolkit   | 3.0.36                |
| shell type       | prompt_toolkit        |
| history backend  | json                  |
| pygments         | 2.14.0                |
| on posix         | True                  |
| on linux         | True                  |
| distro           | unknown               |
| on wsl           | True                  |
| wsl version      | 2                     |
| on darwin        | False                 |
| on windows       | False                 |
| on cygwin        | False                 |
| on msys2         | False                 |
| is superuser     | False                 |
| default encoding | utf-8                 |
| xonsh encoding   | utf-8                 |
| encoding errors  | surrogateescape       |
| xontrib 1        | sh                    |
| xontrib 2        | whole_word_jumping    |
| xontrib 3        | voxapi                |
| xontrib 4        | vox                   |
| xontrib 5        | pdb                   |
| xontrib 6        | xog                   |
| xontrib 7        | coreutils             |
| xontrib 8        | autovox               |
| xontrib 9        | abbrevs               |
| xontrib 10       | fish_completer        |
| xontrib 11       | free_cwd              |
| xontrib 12       | bashisms              |
| RC file 1        | /home/kesnar/.xonshrc |
+------------------+-----------------------+
 Debug level: Off
|-------------------------|-----------|-----------|
|Event name               | Time (s)  | Delta (s) |
|-------------------------|-----------|-----------|
|on_post_prompt           |   0.000   |   0.000   |
|on_precommand            |   0.000   |   0.000   |
|on_postcommand           |   0.007   |   0.006   |
|on_pre_prompt_format     |   0.007   |   0.000   |
|on_pre_prompt_tokenize   |   0.007   |   0.000   |
|on_post_prompt_tokenize  |   0.009   |   0.002   |
|on_pre_prompt_style      |   0.010   |   0.001   |
|on_post_prompt_style     |   0.011   |   0.001   |
|on_pre_prompt            |   0.011   |   0.000   |
|-------------------------|-----------|-----------|

Expected Behavior

Startup time < 1sec.

Current Behavior

Startup time > 2sec.

Showcase

kesnar@glotka ~ $ cat /etc/wsl.conf
[interop]
#appendWindowsPath=false
kesnar@glotka ~ $ echo $PATH
/home/kesnar/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/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/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/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files/dotnet/:/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/Docker/Docker/resources/bin:/mnt/c/Users/kesna/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/kesna/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/kesna/AppData/Local/Microsoft/WinGet/Packages/glzr-io.glazewm_Microsoft.Winget.Source_8wekyb3d8bbwe:/mnt/c/Program Files/Neovim/bin
kesnar@glotka ~ $ ! time xonsh -c exit
<function sys.exit>

real    0m2.922s
user    0m0.282s
sys     0m0.129s
kesnar@glotka ~ $ xonsh --timings
 Debug level: Off
|-------------------------|-----------|-----------|
|Event name               | Time (s)  | Delta (s) |
|-------------------------|-----------|-----------|
|start                    |   0.000   |   0.000   |
|pre_execer_init          |   0.004   |   0.004   |
|post_execer_init         |   0.249   |   0.246   |
|pre_xontribs_autoload    |   0.249   |   0.000   |
|post_xontribs_autoload   |   0.257   |   0.008   |
|on_pre_rc                |   0.257   |   0.000   |
|on_post_rc               |   0.308   |   0.050   |
|on_ptk_create            |   0.324   |   0.016   |
|on_post_init             |   0.324   |   0.000   |
|on_pre_cmdloop           |   0.324   |   0.000   |
|on_pre_prompt_format     |   0.324   |   0.000   |
|on_pre_prompt_tokenize   |   0.333   |   0.010   |
|on_post_prompt_tokenize  |   0.339   |   0.006   |
|on_pre_prompt_style      |   0.373   |   0.034   |
|on_post_prompt_style     |   0.375   |   0.001   |
|on_pre_prompt            |   0.375   |   0.000   |
|-------------------------|-----------|-----------|
kesnar@glotka ~ $ exit

kesnar@glotka ~ $ sudo vi /etc/wsl.conf
kesnar@glotka ~ $ wsl.exe --shutdown

[process exited with code 1 (0x00000001)]
You can now close this terminal with Ctrl+D, or press Enter to restart.

kesnar@glotka ~ $ cat /etc/wsl.conf
[interop]
appendWindowsPath=false
kesnar@glotka ~ $ echo $PATH
/home/kesnar/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib
kesnar@glotka ~ $ ! time xonsh -c exit
<function sys.exit>

real    0m0.198s
user    0m0.160s
sys     0m0.030s
kesnar@glotka ~ $ xonsh --timings
 Debug level: Off
|-------------------------|-----------|-----------|
|Event name               | Time (s)  | Delta (s) |
|-------------------------|-----------|-----------|
|start                    |   0.000   |   0.000   |
|pre_execer_init          |   0.004   |   0.004   |
|post_execer_init         |   0.028   |   0.024   |
|pre_xontribs_autoload    |   0.028   |   0.000   |
|post_xontribs_autoload   |   0.036   |   0.008   |
|on_pre_rc                |   0.036   |   0.000   |
|on_post_rc               |   0.087   |   0.051   |
|on_ptk_create            |   0.096   |   0.010   |
|on_post_init             |   0.097   |   0.000   |
|on_pre_cmdloop           |   0.097   |   0.000   |
|on_pre_prompt_format     |   0.097   |   0.000   |
|on_pre_prompt_tokenize   |   0.120   |   0.024   |
|on_post_prompt_tokenize  |   0.126   |   0.005   |
|on_pre_prompt_style      |   0.144   |   0.019   |
|on_post_prompt_style     |   0.146   |   0.001   |
|on_pre_prompt            |   0.146   |   0.000   |
|-------------------------|-----------|-----------|

Steps to Reproduce

Install WSL in Windows 11 and follow the steps as shown in the above showcase

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@anki-code
Copy link
Member

anki-code commented Mar 24, 2024

The start point to improve the logic is commads_cache.
Probably the way to improve the logic for windows is around reading only .exe files instead of full directory.
As I remember because windows mounts the directory with assigning +x to all files we treat all of these as executable but in fact only .exe files are executable. If it's right we can change the logic for ON_WSL and System32 directory.

@anki-code anki-code changed the title xonsh in WSL, slow startup due to PATH pollution Read System32 from PATH in WSL more picky Mar 24, 2024
@anki-code anki-code changed the title Read System32 from PATH in WSL more picky Windows: Read System32 from PATH in WSL more picky May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants