[PATCHv3 16/16] bash prompt: mention that PROMPT_COMMAND mode is faster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



__git_ps1() is usually added to the prompt inside a command
substitution, imposing the overhead of fork()ing a subshell.  Using
__git_ps1() for $PROMPT_COMMAND is slightly faster, because it avoids
that command substitution.

Mention this in the comments about setting up the git prompt.

The whole series speeds up the bash prompt on Windows/MSysGit
considerably.  Here are some timing results in three scenarios, each
repeated 10 times:

At the top of the work tree, before:

    $ time for i in {0..9} ; do prompt="$(__git_ps1)" ; done

    real    0m1.716s
    user    0m0.301s
    sys     0m0.772s

  After:

    real    0m0.687s
    user    0m0.075s
    sys     0m0.396s

  After, from $PROMPT_COMMAND:

    $ time for i in {0..9} ; do __git_ps1 '\h:\w' '$ ' ; done

    real    0m0.546s
    user    0m0.075s
    sys     0m0.181s

At the top of the work tree, detached head, before:

    real    0m2.574s
    user    0m0.376s
    sys     0m1.207s

  After:

    real    0m1.139s
    user    0m0.151s
    sys     0m0.500s

  After, from $PROMPT_COMMAND:

    real    0m1.030s
    user    0m0.245s
    sys     0m0.336s

In a subdirectory, during rebase, stash status indicator enabled,
before:

    real    0m3.557s
    user    0m0.495s
    sys     0m1.767s

  After:

    real    0m0.717s
    user    0m0.120s
    sys     0m0.300s

  After, from $PROMPT_COMMAND:

    real    0m0.577s
    user    0m0.047s
    sys     0m0.258s

On Linux the speedup ratio is comparable to Windows, but overall it
was about an order of magnitude faster to begin with.  The last case
from above, repeated 100 times, before:

    $ time for i in {0..99} ; do prompt="$(__git_ps1)" ; done

    real    0m2.806s
    user    0m0.180s
    sys     0m0.264s

  After:

    real    0m0.857s
    user    0m0.020s
    sys     0m0.028s

Signed-off-by: SZEDER Gábor <szeder@xxxxxxxxxx>
---
 contrib/completion/git-prompt.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 7152ae49..daed6a1d 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -15,11 +15,11 @@
 #        Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
 #        ZSH:  PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
 #        the optional argument will be used as format string.
-#    3b) Alternatively, if you are using bash, __git_ps1 can be
-#        used for PROMPT_COMMAND with two parameters, <pre> and
-#        <post>, which are strings you would put in $PS1 before
-#        and after the status string generated by the git-prompt
-#        machinery.  e.g.
+#    3b) Alternatively, for a slighly faster prompt, if you are
+#        using bash, __git_ps1 can be used for PROMPT_COMMAND
+#        with two parameters, <pre> and <post>, which are strings
+#        you would put in $PS1 before and after the status string
+#        generated by the git-prompt machinery.  e.g.
 #        Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
 #        ZSH:  precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
 #        will show username, at-sign, host, colon, cwd, then
-- 
1.8.3.1.599.g4459181

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]