cmder: Lag returning to prompt (especially) in git repo

When using cmder with git (where it shows the name of my currently checked out branch next to the location), I’m finding that my commands are executed quickly but there is a major delay returning to the prompt so I can enter in another command. I notice this to some extent when I’m not in a git repo, but then the delay is almost not noticeable (100-200ms I’d guess), as opposed to 1-2 seconds in a repo.

To give further details, in my repo if I type ls, the file list comes up immediately, then the current tab changes from saying “cmd.exe” to “git.exe”, and only after 1-2 seconds do I get a lambda prompt again where I can enter further commands.

I’m running Windows 8.1 and cmder.exe is installed in Program Files. Let me know if any more details would be helpful.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 41 (9 by maintainers)

Commits related to this issue

Most upvoted comments

After some searching, I’ve been able to remove git integration in the prompt, resulting in no lag when inputting commands in a git repo! The following modifications must be done to your cmder/vender/clink.lua file:

On line 41, remove {git}{hg} to prevent git/mercurial branch from being printed in your prompt:

local cmder_prompt = "\x1b[1;32;40m{cwd}\n\x1b[1;30;40m{lamb} \x1b[0m"

Comment out lines 266-267 to prevent git and mercurial plugins from running every time you press enter:

--clink.prompt.register_filter(hg_prompt_filter, 50)
--clink.prompt.register_filter(git_prompt_filter, 50)

As a note, you may want to back up this clink.lua file somewhere, in case it gets overridden after a cmder update.

Hope this helps!

In the traditional cmd with clink, there are two git look-ups run in clink.lua to refresh the prompt:

  • get_git_branch - fast, reads .git/HEAD
  • get_git_status - slow, git status which is used to decide about dirty/clean colourisation. In the whole git repo of Boost, this one takes annoyingly long time.

So, instead of disabling git information in the prompt completely, some may prefer to just get rid of the detailed/coloured status, keeping the current branch info:

λ diff -Nua c:\apps\cmder_mini\vendor\clink.lua.original c:\apps\cmder_mini\vendor\clink.lua
--- c:\apps\cmder_mini\vendor\clink.lua.original        2018-04-09 09:54:20.468732700 +0200
+++ c:\apps\cmder_mini\vendor\clink.lua 2018-04-10 08:39:57.809013700 +0200
@@ -263,11 +263,12 @@
         local color
         if branch then
             -- Has branch => therefore it is a git folder, now figure out status
-            if get_git_status() then
-                color = colors.clean
-            else
-                color = colors.dirty
-            end
+            -- XXX: Disable git status due to lag in large repo
+            -- if get_git_status() then
+                 color = colors.clean
+            -- else
+            --     color = colors.dirty
+            -- end

             clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
             return false

Kudos to https://github.com/cmderdev/cmder/issues/447#issuecomment-244149494 for inspiration.

@DGalt Try this

  • edit vendor\profile.ps1
  • find this bit
[ScriptBlock]$CmderPrompt = {
    $Host.UI.RawUI.ForegroundColor = "White"
    Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
    checkGit($pwd.ProviderPath)
}
  • remove checkGit($pwd.ProviderPath)
  • save and relaunch cmder

I’d also like a way to disable git looking at my current repo as it gives me 30+ sec delay. It’s a massive repo. I really don’t care about it telling me i’m in the master branch.

How can I disable any git stuff. I just want a command prompt.

I’d like to have an option to disable git showing anything on the prompt. It still slow on some occasions.

Can the dev re-open this issue? It’s still a problem and all ‘fixes’ here are overwritten on an update. This belongs somewhere in settings than hardcoded in a profile.ps1 script.

Just to summarize the quick solution in 2019, this definitely solved my complaint with Cmder, that it took over 8 seconds every time I issued a command!

  • Incidentally I had Settings -> Update -> “Preferred release type” set to “Stable” which was ConEmu 180626 that came from years ago - the developer might want to note this; I changed to “Latest”, so I don’t short-change myself for the coming few years, but this did not make any performance difference
  • Go to C:\Program Files\Cmder\vendor, make a backup copy of clink.lua and edit it
  • In “git_prompt_filter()”, delete the lines containing these:
  get_git_status()
  get_git_conflict()
  • Just leave these lines in place:
        if branch then
            color = colors.clean
            clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
            return false
        end

Now commands are responsive! Instantaneous! Thank you to: @mloskot @justaniles Sep 1, 2016 https://github.com/cmderdev/cmder/issues/447#issuecomment-244149494

Is this post still the most up to date advice for this? Is there a configuration option to remove the SCM details from the prompt?

My bad, the diff had me confused. Would’ve been better if you included the output without diff in the first place. Either way thanks. And apologies. Have a nice day.

The earlier tweak does not work for Cmder 1.3.11, but it should be easy to adjust the new versions of the get_git_status and get_git_conflict.

For large repos with lots of submodules, like https://github.com/boostorg/boost/, these two tweaks are sufficient for me to greatly speed the git prompt:

Simply, add --ignore-submodules to these two git commands:

https://github.com/cmderdev/cmder/blob/89499f2a6068980256ca1132714407fdbcdc282a/vendor/clink.lua#L221-L222

https://github.com/cmderdev/cmder/blob/89499f2a6068980256ca1132714407fdbcdc282a/vendor/clink.lua#L236-L237

In the traditional cmd with clink, there are two git look-ups run in clink.lua to refresh the prompt:

  • get_git_branch - fast, reads .git/HEAD
  • get_git_status - slow, git status which is used to decide about dirty/clean colourisation. In the whole git repo of Boost, this one takes annoyingly long time.

So, instead of disabling git information in the prompt completely, some may prefer to just get rid of the detailed/coloured status, keeping the current branch info:

λ diff -Nua c:\apps\cmder_mini\vendor\clink.lua.original c:\apps\cmder_mini\vendor\clink.lua
--- c:\apps\cmder_mini\vendor\clink.lua.original        2018-04-09 09:54:20.468732700 +0200
+++ c:\apps\cmder_mini\vendor\clink.lua 2018-04-10 08:39:57.809013700 +0200
@@ -263,11 +263,12 @@
         local color
         if branch then
             -- Has branch => therefore it is a git folder, now figure out status
-            if get_git_status() then
-                color = colors.clean
-            else
-                color = colors.dirty
-            end
+            -- XXX: Disable git status due to lag in large repo
+            -- if get_git_status() then
+                 color = colors.clean
+            -- else
+            --     color = colors.dirty
+            -- end

             clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
             return false

Kudos to #447 (comment) for inspiration.

For me, commenting the if-else block caused an error due to color property can’t be found. I just removed the color.. property on the string.gsub call like this:

clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "("..branch..")")

@daxgames Disabling git status in clink.lua is workaround for wherever clink.lua is used. In this context here it is for Cmder.

My apologies, I wasn’t clear. In my earlier comment, I just wanted to explain that I don’t see any connection between the general slowness of git status that also affects Clink/Cmder and the slowness of Unix tools reported elsewhere.

To summarise, the problem we are discussing here is related to git command and is very simple:

  • Current implementation of git status is intrinsically slow for large and submodule-arised repos
  • Cmder’s clink.lua relies on git status, hence the prompt update lags
  • Workaround: disable git status calls from clink.lua to avoid the lags

Re: @rohitkrishna094 's https://github.com/cmderdev/cmder/issues/447#issuecomment-536690719

This is certainly not a competition but that comment may leave one quite confused.

AFAICT, the patch I presented in https://github.com/cmderdev/cmder/issues/447#issuecomment-379992066 produces this code

         if branch then
             -- Has branch => therefore it is a git folder, now figure out status
             -- XXX: Disable git status due to lag in large repo
             -- if get_git_status() then
                 color = colors.clean
             -- else
             --     color = colors.dirty
             -- end

             clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
             return false

which, clearly, is the equivalent code to the code @TimRudy presented in https://github.com/cmderdev/cmder/issues/447#issuecomment-532752032

        if branch then
            color = colors.clean
            clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
            return false

@rohitkrishna094 I’d suggest you analyse the snippets more carefully, then you should avoid any disappointments.