zsh-workers
 help / color / mirror / code / Atom feed
From: "Jörg Sommer" <joerg@alea.gnuu.de>
To: zsh-workers@sunsite.dk
Subject: [PATCH] Re: git completion is really slow for some git commands.
Date: Mon, 13 Oct 2008 00:53:40 +0000 (UTC)	[thread overview]
Message-ID: <slrngf54b6.r2h.joerg@alea.gnuu.de> (raw)
In-Reply-To: <1223557300.563.31.camel@localhost.localdomain>

Hello Brice,

Brice Figureau <brice+zsh@daysofwonder.com> wrote:
> Unfortunately git completion, although working fine, is extremely slow
> as soon as you have a moderately sized git repository. In my case, my
> checkout have 13000 files and about 6000 commits.
>
> git log <TAB> takes about 15s using 100% CPU to complete on my 2.4GHZ P4
> computer. OK, that's now an old computer, but I find that a little bit
> slow to just sort/split 13000 strings.
>
> It all boils down to the following chain of events:
>  * git log completion uses __git_files
>
>  * _git_files uses "git ls-files". In itself ls-files on this repository
> on cold cache takes about 70ms (which is short, compared to the 15s of
> the whole thing).
>
>  * the result of git ls-files is splitted by \0 and stored in a shell
> array. This operation takes about 350ms. That's still fast compared to
> the 15s of the whole execution time. Note: that's not as fast we would
> think it could be.
>
>  * this shell array is then passed to _multi_parts for path splitting of
> each element. This is this operation that takes age. As soon as I change
> the _multi_parts code to just call a naive compadd and return, the
> completion is (almost) immediate, and seems to work fine.

Can you try this patch? It doesn't change anything if you didn't specify
anything, i.e. git log -- <TAB> takes still very long. But it optimizes
the case when you specify anything. Try git log -- some/thing<TAB>.

commit e985683fe8d805228ad88903261f20181de23f1e
Author: Jörg Sommer <joerg@alea.gnuu.de>
Date:   Mon Oct 13 01:58:03 2008 +0200

    Prefilter the completion for _multi_parts
    
    The _multi_parts function consumes very much time, if the array with the
    possible completions is large. This happens often in large git
    repositories like the kernel git repository. To reduce the workload of
    _multi_parts filter out does entries from the array, they aren't possible
    completions. When the user specifies the path foo/bar only consider paths
    matching the pattern foo*/bar*.

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index c617613..5fd637a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2761,6 +2761,7 @@ __git_files () {
   files=(${(ps:\0:)"$(_call_program files git ls-files -z $ls_opts $opts 2>/dev/null)"})
   __git_command_successful || return
 
+  [[ -n $PREFIX ]] && files=${(M)files:#${~PREFIX//\//*/}*}
   _wanted files expl 'index file' _multi_parts $@ - / files
 }
 
@@ -2859,6 +2860,7 @@ __git_tree_files () {
   fi
 
   local expl
+  [[ -n $PREFIX ]] && tree_files=${(M)tree_files:#${~PREFIX//\//*/}*}
   _wanted files expl 'tree file' _multi_parts -f $@ -- / tree_files
 }
 

Question to everybody else: Should such a filter go to _multi_parts
itself?

Bye, Jörg.
-- 
Alles, wovor wir Angst haben müssen, ist die Angst selbst.
       	     	       	     	     	 (Franklin D. Roosevelt)


  reply	other threads:[~2008-10-13  1:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-09 13:01 Brice Figureau
2008-10-13  0:53 ` Jörg Sommer [this message]
2008-10-13  8:15   ` [PATCH] " Brice Figureau
2008-10-13 15:01     ` Jörg Sommer
2008-10-13 15:45       ` Brice Figureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrngf54b6.r2h.joerg@alea.gnuu.de \
    --to=joerg@alea.gnuu.de \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).