* [PATCH] git-completion.bash - avoid excruciatingly slow ref completion on Cygwin
@ 2014-10-11 15:51 Mark Levedahl
2014-10-18 14:47 ` Tay Ray Chuan
0 siblings, 1 reply; 2+ messages in thread
From: Mark Levedahl @ 2014-10-11 15:51 UTC (permalink / raw)
To: git; +Cc: Mark Levedahl
$git checkout <tab> was taking about 3.5 seconds to respond on one
repository having four remotes with about 100 total refs (measured on
Cygwin). All of the time was being claimed in "git for-each-ref" to do
its work. This working directory was created using git-new-workdir, and
thus .git/refs and .git/packed-refs are both symlinks. for-each-ref
operates in a way that causes the .git/refs symlink to be resolved
multiple times for each ref in the repository, and Cygwin is especially
slow in such operations.
Patching refs.c to avoid repeatedly dereferencing the symlink reduced
execution time from about 3.5 seconds to about 1.1 seconds (but no
improvement on Linux), while an alternate approach of replacing the
ref-list expansion with a shell pipeline provides a larger improvement on
Cygwin and also improves Linux. So, the shell pipeline approach is
provided here.
Relevant timing results using the same repository on both Linux and
Cygwin:
On Cygwin:
$ time git for-each-ref --format="%(refname:short)" refs
real 0m3.523s
user 0m0.436s
sys 0m2.733s
$ time (cd "$GIT_DIR" ; cat packed-refs ; find refs/ -type f) \
2>/dev/null | sed -ne 's@^.*refs/@refs/@p' | sort | uniq
real 0m0.503s
user 0m0.307s
sys 0m0.139s
On Linux (essentially the same hardware):
$ time git for-each-ref --format="%(refname:short)" refs
real 0m0.020s
user 0m0.006s
sys 0m0.014s
$ time (cd "$GIT_DIR" ; cat packed-refs ; find refs/ -type f) \
2>/dev/null | sed -ne 's@^.*refs/@refs/@p' | sort | uniq
real 0m0.012s
user 0m0.006s
sys 0m0.005s
So, this is a win even on Linux, but more importantly it makes use of
tab completion tolerable on Cygwin when symlinks are involved.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
contrib/completion/git-completion.bash | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 965778e..62d976e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -319,8 +319,9 @@ __git_heads ()
{
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
- git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
- refs/heads
+ (cd "$dir" ; cat packed-refs ; find refs/heads -type f) 2>/dev/null |
+ sed -ne 's@^.*refs/heads/@@p' |
+ sort -u
return
fi
}
@@ -329,8 +330,9 @@ __git_tags ()
{
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
- git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
- refs/tags
+ (cd "$dir" ; cat packed-refs ; find refs/tags -type f) 2>/dev/null |
+ sed -ne 's@^.*refs/tags/@@p' |
+ sort -u
return
fi
}
@@ -348,17 +350,21 @@ __git_refs ()
format="refname"
refs="${cur%/*}"
track=""
+ (cd "$dir" ; cat packed-refs ; find refs/ -type f) 2>/dev/null |
+ sed -ne 's@^.*refs/@refs/@p' |
+ sort -u
+ return
;;
*)
for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
if [ -e "$dir/$i" ]; then echo $i; fi
done
- format="refname:short"
- refs="refs/tags refs/heads refs/remotes"
+ (cd "$dir" ; cat packed-refs ; find refs/ -type f) 2>/dev/null |
+ sed -rne 's@^.*refs/(heads|remotes|tags)/@@p' |
+ sort -u
+ return
;;
esac
- git --git-dir="$dir" for-each-ref --format="%($format)" \
- $refs
if [ -n "$track" ]; then
# employ the heuristic used by git checkout
# Try to find a remote branch that matches the completion word
--
2.1.2.2.0.14
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] git-completion.bash - avoid excruciatingly slow ref completion on Cygwin
2014-10-11 15:51 [PATCH] git-completion.bash - avoid excruciatingly slow ref completion on Cygwin Mark Levedahl
@ 2014-10-18 14:47 ` Tay Ray Chuan
0 siblings, 0 replies; 2+ messages in thread
From: Tay Ray Chuan @ 2014-10-18 14:47 UTC (permalink / raw)
To: Mark Levedahl; +Cc: Git Mailing List, msysgit@googlegroups.com
On Sat, Oct 11, 2014 at 11:51 PM, Mark Levedahl <mlevedahl@gmail.com> wrote:
>
> $git checkout <tab> was taking about 3.5 seconds to respond on one
> repository having four remotes with about 100 total refs (measured on
> Cygwin). All of the time was being claimed in "git for-each-ref" to do
> its work. This working directory was created using git-new-workdir, and
> thus .git/refs and .git/packed-refs are both symlinks. for-each-ref
> operates in a way that causes the .git/refs symlink to be resolved
> multiple times for each ref in the repository, and Cygwin is especially
> slow in such operations.
Thanks for looking into this.
> Patching refs.c to avoid repeatedly dereferencing the symlink reduced
> execution time from about 3.5 seconds to about 1.1 seconds (but no
> improvement on Linux),
This makes your patch sound bad, but it isn't when one realises it is
already fast on Linux!
> [snip]
>
> Relevant timing results using the same repository on both Linux and
> Cygwin:
FWIW, timings on msysgit:
$ time git for-each-ref --format="%(refname:short)" refs
real 0m8.799s
user 0m0.109s
sys 0m0.250s
$ time (cd "$GIT_DIR" ; cat packed-refs ; find refs/ -type f) \
2>/dev/null | sed -ne 's@^.*refs/@refs/@p' | sort | uniq
real 0m3.406s
user 0m1.073s
sys 0m2.398s
so while your symlink-analysis might not accurately describe msysgit
(I believe copies are made in place of a symlink), msysgit benefits
from this too.
--
Cheers,
Ray Chuan
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-18 14:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-11 15:51 [PATCH] git-completion.bash - avoid excruciatingly slow ref completion on Cygwin Mark Levedahl
2014-10-18 14:47 ` Tay Ray Chuan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).