JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.38k forks source link

Performance with WSL2 is extremely slow in a GitHub repo #1144

Closed grantcv1 closed 3 years ago

grantcv1 commented 3 years ago

Code of Conduct

What happened?

When I enter into a directory that is associated with a GitHub repo, the performance slows considerably.

I've found other issues squabbling over performance issues, but those issues seems to be less that one second delays.

In my case, it takes the prompt about 10 seconds to return after the command has finished executing. This only occurs in a GitHub repo.

I am observing the same problem in Windows Terminal and in the VSCode Terminal window, using the WSL Ubuntu shells. The PowerShell prompt has a noticeable pause, but it's a fraction of a second.

I am running from a WSL2 Ubuntu bash shell and looking into a GitHub repo on my Windows filesystem mounted into the Ubuntu environment. VSCode is running in Windows using a WSL2 Ubuntu bash shell.

I have tried to see if anything is out of the ordinary in the on-my-posh.log file, but aside from a very slow getenv time, there doesn't seem to be anything useful in it.

FWIW, I'm new to both WSL2 and oh-my-posh this weekend, so pilot error is a definite possibility.

Version

5.16.4

Theme

blue-owl, but other themes have the same problem.

What OS are you seeing the problem on?

Windows

Which shell are you using?

bash

Relevant log output

2021/10/31 21:18:20 #### start oh-my-posh run ####
2021/10/31 21:18:20 getenv duration: 1.1µs, args: XDG_CACHE_HOME
2021/10/31 21:18:20 getCachePath duration: 325.2µs, args:
2021/10/31 21:18:20 #### end oh-my-posh run ####
2021/10/31 21:21:54 #### start oh-my-posh run ####
2021/10/31 21:21:54 getenv duration: 700ns, args: XDG_CACHE_HOME
2021/10/31 21:21:54 getCachePath duration: 279.4µs, args:
2021/10/31 21:21:54 #### end oh-my-posh run ####
2021/10/31 21:33:07 #### start oh-my-posh run ####
2021/10/31 21:33:07 getenv duration: 900ns, args: XDG_CACHE_HOME
2021/10/31 21:33:07 getCachePath duration: 267.3µs, args:
2021/10/31 21:33:07 #### end oh-my-posh run ####
JanDeDobbeleer commented 3 years ago

@grantcv1 I do not see a slow getenv time, nor indications any log statements for the git repo? Is the repo's location on the shared drive inside WSL2? Because then it will fall back to git.exe and that can be very, very slow depending on where the executable is inside the PATH. I'll need more information from the debug logs also showing where it's spending time, if there's nothing directly strange in there I would check where oh-my-posh is installed and if calling the binary might be a problem (slow startup time due to network disk or something else).

grantcv1 commented 3 years ago

@JanDeDobbeleer The repo is in my normal Windows user folder that is automounted into WSL2.

My path is quite long as my configuration appends the Windows path to the Ubuntu path. By my count, I end up with 43 entries, most of which are Windows paths. My Ubuntu side is quite basic as it's a fresh configuration. I have the wsl.conf file configured to append the Windows Path, but it appeared it was doing that before I fiddled with wsl.conf anyway.

I've tried moving the Git path entries on the Windows side up to the very top of the list (so that it becomes the ninth entry in the appended list on the Ubuntu side), but that hasn't made any difference.

On the Ubuntu side, git is at /usr/bin/git and oh-my-posh is at /usr/local/bin/oh-my-posh. On the Windows side, git is at c:\Program Files\Git\cmd.

I don't understand how Git on Windows and Git on Ubuntu play together in a WSL2 configuration.

The log I provided is the only log I know about. I deleted it and then let it recreate it so I could see if it was corresponding to the commands I was executing. But what you see there is what all the entries looked like. The reason I thought the getenv was slow was that I misread the ns as ms -- my mistake. If there is another log, I can dig it up for you.

I'm not sure if this is important, but on Saturday the performance was fine, but the GitHub branch was refusing to show at all (it worked fine in PowerShell on the WIndows side). After a restart on Sunday, the Ubuntu prompt started showing the GitHub branch, but was horrendously slow.

This is all running on my personal laptop (i9 processor, 64GB RAM, ThinkPad) so there should be no network latency to my hard disk.

JanDeDobbeleer commented 3 years ago

@grantcv1 it would be really helpful to get the log from the folder where you see the issue. So, navigate to the repo where the issue is and run /usr/local/bin/oh-my-posh --debug --config <you config path> --shel uni. Then oh-my-posh.log should contain what we're looking for.

grantcv1 commented 3 years ago

I got this report:

Here are the timings of segments in your prompt:

ConsoleTitle(true) - 3 ms - LegisPro3 @ ASTERIX root(false) - 0 ms - os(true) - 0 ms - WSL -  path(true) - 1 ms -  ransparentm  ransparentm  LegisPro3  git(true) - 7880 ms - ransparentm feature-legispro-696  executiontime(true) - 0 ms -  0s  exit(false) - 0 ms - session(true) - 0 ms -  grantcv1ransparentm / ASTERIX time(true) - 0 ms - ransparentm  09:08:58 exit(true) - 0 ms - ❯

oh-my-posh.log reads:

2021/11/03 09:08:50 #### start oh-my-posh run #### 2021/11/03 09:08:50 getenv duration: 1.1µs, args: XDG_CACHE_HOME 2021/11/03 09:08:50 getCachePath duration: 335.1µs, args: 2021/11/03 09:08:50 getArgs duration: 200ns, args: 2021/11/03 09:08:50 getArgs duration: 200ns, args: 2021/11/03 09:08:50 getShellName duration: 500ns, args: 2021/11/03 09:08:50 isRunningAsRoot duration: 500ns, args: 2021/11/03 09:08:50 getcwd duration: 299.1µs, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 100ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 300ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 300ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 100ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 300ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getShellName duration: 300ns, args: 2021/11/03 09:08:50 getCurrentUser duration: 1.6µs, args: 2021/11/03 09:08:50 getHostName duration: 1.5µs, args: 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 isRunningAsRoot duration: 500ns, args: 2021/11/03 09:08:50 getcwd duration: 200ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getenv duration: 900ns, args: WSL_DISTRO_NAME 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 getcwd duration: 200ns, args: 2021/11/03 09:08:50 getArgs duration: 300ns, args: 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 300ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 300ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getArgs duration: 200ns, args: 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getenv duration: 900ns, args: WSL_DISTRO_NAME 2021/11/03 09:08:50 isWsl duration: 122.9µs, args: 2021/11/03 09:08:50 getcwd duration: 300ns, args: 2021/11/03 09:08:50 hasCommand duration: 17.5µs, args: git 2021/11/03 09:08:50 getcwd duration: 200ns, args: 2021/11/03 09:08:50 hasParentFilePath duration: 635.7µs, args: .git 2021/11/03 09:08:50 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:50 getenv duration: 1.1µs, args: WSL_DISTRO_NAME 2021/11/03 09:08:50 isWsl duration: 115.8µs, args: 2021/11/03 09:08:50 getcwd duration: 200ns, args: 2021/11/03 09:08:58 runCommand duration: 7.8710049s, args: git --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --short --branch 2021/11/03 09:08:58 hasFolder duration: 486µs, args: /win/c/Users/grantcv1/Projects/LegisPro3/.git/rebase-merge 2021/11/03 09:08:58 hasFolder duration: 444.6µs, args: /win/c/Users/grantcv1/Projects/LegisPro3/.git/rebase-apply 2021/11/03 09:08:58 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:58 hasFilesInDir duration: 683.7µs, args: MERGE_MSG 2021/11/03 09:08:58 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:58 hasFilesInDir duration: 623µs, args: CHERRY_PICK_HEAD 2021/11/03 09:08:58 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:58 hasFilesInDir duration: 626.2µs, args: REVERT_HEAD 2021/11/03 09:08:58 getPathSeperator duration: 200ns, args: 2021/11/03 09:08:58 hasFilesInDir duration: 543µs, args: sequencer/todo 2021/11/03 09:08:58 getFileContent duration: 2.0921ms, args: /win/c/Users/grantcv1/Projects/LegisPro3/.git/logs/refs/stash 2021/11/03 09:08:58 getFileContent duration: 1.4083ms, args: /win/c/Users/grantcv1/Projects/LegisPro3/.git/HEAD 2021/11/03 09:08:58 getcwd duration: 200ns, args: 2021/11/03 09:08:58 executionTime duration: 500ns, args: 2021/11/03 09:08:58 getcwd duration: 200ns, args: 2021/11/03 09:08:58 lastErrorCode duration: 200ns, args: 2021/11/03 09:08:58 getcwd duration: 200ns, args: 2021/11/03 09:08:58 getCurrentUser duration: 700ns, args: 2021/11/03 09:08:58 getRuntimeGOOS duration: 200ns, args: 2021/11/03 09:08:58 getHostName duration: 1.3µs, args: 2021/11/03 09:08:58 getenv duration: 800ns, args: SSH_CONNECTION 2021/11/03 09:08:58 getenv duration: 600ns, args: SSH_CLIENT 2021/11/03 09:08:58 getenv duration: 600ns, args: POSH_SESSION_DEFAULT_USER 2021/11/03 09:08:58 getcwd duration: 200ns, args: 2021/11/03 09:08:58 getcwd duration: 200ns, args: 2021/11/03 09:08:58 lastErrorCode duration: 200ns, args: 2021/11/03 09:08:58 lastErrorCode duration: 100ns, args: 2021/11/03 09:08:58 lastErrorCode duration: 200ns, args: 2021/11/03 09:08:58 #### end oh-my-posh run ####

JanDeDobbeleer commented 3 years ago

@grantcv1 found the culprit (as expected): git --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --short --branch how long does that command take when you execute it directly?

boarder2 commented 3 years ago

@grantcv1 When you access a Windows file system from within WSL2, IO performance is very poor. More info here: https://github.com/microsoft/WSL/issues/4197#issuecomment-604592340

IO performance will be MUCH, MUCH better if you clone your repository into the ext4 filesystem within the WSL2 VHD itself.

OMP can't do much here since the problem lies within the WSL2 limitations.

grantcv1 commented 3 years ago

@JanDeDobbeleer When I run that command I get this:

❯ git --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --short --branch Refresh index: 100% (303/303), done.

develop...origin/develop [ahead 1, behind 1]

M .gitignore .... (Omitted for privacy reasons) M styles/ReleaseNotes.css WSL -       LegisPro3  develop  15.946s   grantcv1 / ASTERIX  10:03:04 ❯

JanDeDobbeleer commented 3 years ago

@grantcv1 do you have the timing of that command too?

JanDeDobbeleer commented 3 years ago

Closing due to the fact that it is indeed a Windows path and known issue in WSL2.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.