excrutiatingly slow on msys2/cygwin
msys2 is the unix-like user environment based on cygwin for building native windows apps, and is also slightly nicer than cygwin for just having a unix shell and tools and interacting with windows:
http://msys2.github.io/
this project works fine in msys2, but it is incredibly slow, the prompt is too painful to use. I'm guessing it is the same problem on cygwin since msys2 is basically cygwin with some minor changes.
The problem is forking, since there is no way to emulate copy-on-write fork() in Win32, cygwin uses a much slower method of implementing this family of syscalls. This of course is especially noticeable with shell projects which rely on shelling-out to system utilities.
If I find the time and inclination, I will try to look for opportunities to reduce shelling-out and for caching more things to improve the performance on cygwin and cygwin-likes.
Awesome, that would be cool. It is also very slow in the Linux subsystem for Windows.
I'm currently trying to take a more native approach here (see the Native branch) which hopefully will speed the things a lot up. This is WIP (currently on .NET but still undecided, maybe I will go the C/C++ route)
As a workaround on Windows 10, I am using Ubuntu under WSL, which provides a little bit of performance increase. But comparing to native Linux and MacOS it's still slow.
Any update on the native approach?
Thanks.
Things like WSL still suffer from using a slow virtual filesystem, and this is telling with git because it is very heavy on file IO.
I did some more work on my simple prompt, which at least looks nice and shows the git branch and exit status, but does not have any of the other git features:
https://github.com/rkitover/bash-msys2-prompt-simple
For the native approach, you would need to learn powershell, and use some kind of powershell git prompt with completely native git for windows binaries, I don't know if this exists or not, it probably does.
I think there's a chance we can optimize the bash code in this project to be more responsive, I'm sorry I haven't quite gotten around to doing any work on this.
@tigerinus Unfortunately the native approach doesn't seemed to help.
if I execute the gitstatus.sh it is fast enough, even on Windows.
I think we have to optimize the gitprompt.sh here. It seems there is to much going on here for the prompt. I'm currently looking into it.
Oh nice, thank you.
Keep in mind that "git for windows" is msys2 git for the most part, so the git operations will still be slow and there's not much to do about this.
I think this port is completely native, but most people don't use this: https://git-scm.com/download/win
So i tried to profile this but unfortunately the most time is indeed consumed by the git calls, so I cannot do much about it. I will optimize the gitprompt,sh a bit that no so much sourcing etc. is going on but that would be just a marginal optimization.
@rkitover The download you mentioned is for the normal Windows system. The bash prompt would IMHO still use the msys/cygwin version. But even in WSL the prompt is slow as heck
In WSL, I currently have acceptable timings (about .5s) after removing the Windows path from the Ubuntu $PATH.
Hi, I'm the maintainer for Git for Cygwin, which shares a lot of the same underlying infrastructure as Git for Windows or Msys2. Unfortunately, any significant improvement here is likely to need to come from Git itself: Git wasn't originally designed for Windows, and things that are fast and easy on *nix systems are frequently slow on Windows. That is getting significantly better over time, but it's a long project and I'm not expecting to see rapid improvement.
If you use WSL2, and only use bash-git-prompt within the WSL filesystem, rather than the Windows filesystem, you might find things are significantly quicker, as WSL2 provides a *nix-native disk which is much quicker for the sorts of file operations Git performs than NTFS is. But if you're on anything that's interfacing with the NTFS disk (or, worse, anything FAT-based) you're likely to find any Git operations are relatively slow, and anything that tries to search the entire worktree – as bash-git-prompt needs to for every prompt – are particularly painful.
(Disclaimer, since this is a context in which it's particularly likely to be relevant: I am a Microsoft employee, but I work doing telecoms stuff in Azure for Operators. I have no knowledge of anything Microsoft or GitHub are doing that isn't public knowledge; my involvement in Cygwin and Git is purely as an OSS contributor doing the things in my own time that I've been doing for years before I started working for Microsoft.)
Hi guys, well it's been like 6 years since I opened this thread, so I wanted to share some notes on what I have been doing.
I no longer use MSYS2 for Windows development, and use the new Windows Terminal with PowerShell.
I am working on a guide for Linux devs about how to do this:
https://github.com/rkitover/windows-dev-guide
In PowerShell I use a git prompt called posh-git, which you can find here:
https://github.com/dahlbyk/posh-git
it has some of the features of this project, as well as some other things like completions. I recommend getting the master from GitHub instead of the PSGallery version.
I have a theme for this prompt which is in my guide, if you'd like to try it, clone posh-git first:
mkdir ~/source/repos -ea ignore
cd ~/source/repos
git clone https://github.com/dahlbyk/posh-git
and put the following in your $profile:
# "Windows PowerShell" does not support the `e special character sequence for Escape, so we use a variable $e for this.
$e = [char]27
import-module ~/source/repos/posh-git/src/posh-git.psd1
function global:PromptWriteErrorInfo() {
if ($global:gitpromptvalues.dollarquestion) {
"$e[0;32mv$e[0m"
}
else {
"$e[0;31mx$e[0m"
}
}
$gitpromptsettings.defaultpromptabbreviatehomedirectory = $true
$gitpromptsettings.defaultpromptpath.foregroundcolor = 0xC4A000
$gitpromptsettings.defaultpromptprefix.text = '$(PromptWriteErrorInfo) '
$username = $env:USERNAME
$hostname = $env:COMPUTERNAME.tolower()
$gitpromptsettings.defaultpromptwritestatusfirst = $false
$gitpromptsettings.defaultpromptbeforesuffix.text = "`n$e[0m$e[38;2;140;206;250m$username$e[1;97m@$e[0m$e[38;2;140;206;250m$hostname "
$gitpromptsettings.defaultpromptsuffix.foregroundcolor = 0xDC143C
$gitpromptsettings.windowtitle = $null
$host.ui.rawui.windowtitle = $hostname
import-module psreadline
set-psreadlineoption -editmode emacs
set-psreadlinekeyhandler -key tab -function complete
set-psreadlinekeyhandler -key uparrow -function historysearchbackward
set-psreadlinekeyhandler -key downarrow -function historysearchforward
. This works in both powershell-core (7.2+) and Windows PowerShell (5.x+).
I actually like this theme better than the one I did previously for this repo, so I'm going work on a new PR now to port it.
UPDATE: I opened a PR here with my new theme, see #485.
Well I didn't notice that this repo is not active anymore.
But I wanted to mention that I made some improvements to my simple and much faster prompt here:
https://github.com/rkitover/sh-prompt-simple
it has a clean/dirty indicator now, when enabled it's still twice as fast as this prompt. It can be dynamically enabled/disabled, and when disabled with the prompt displaying the branch only it's almost instant.