git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "SZEDER Gábor" <szeder@ira.uka.de>
Cc: Felipe Contreras <felipe.contreras@gmail.com>,
	git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 3/3] completion: improve shell expansion of items
Date: Thu, 27 Sep 2012 02:43:38 -0400	[thread overview]
Message-ID: <20120927064338.GA4789@sigill.intra.peff.net> (raw)
In-Reply-To: <20120927062855.GA22890@sigill.intra.peff.net>

On Thu, Sep 27, 2012 at 02:28:55AM -0400, Jeff King wrote:

> Thanks for reminding me to time. I noticed your a31e626 while digging in
> the history, but forgot that I wanted to do a timing test. Sadly, the
> results are very discouraging. Doing a similar test to your 10,000-refs,
> I get:
> 
>   $ refs=$(seq 1 10000)
> 
>   $ . git-completion.bash.old
>   $ time __gitcomp_nl "$refs"
>   real    0m0.065s
>   user    0m0.064s
>   sys     0m0.004s
> 
>   $ . git-completion.bash.new
>   $ time __gitcomp_nl "$refs"
>   real    0m1.799s
>   user    0m1.828s
>   sys     0m0.036s
> 
> So, a 2700% slowdown. Yuck.
> 
> I also tried running it through sed instead of iterating in bash. I know
> that some people will not like the fork, but curiously enough, it was
> not that much faster. Which makes me wonder if part of the slowdown is
> actually bash unquoting the result in compgen.

Ah. The problem is that most of the load comes from my patch 4/3, which
does a separate iteration. Here are the numbers after just patch 3:

  $ time __gitcomp_nl "$refs"
  real    0m0.344s
  user    0m0.392s
  sys     0m0.040s

Slower, but not nearly as painful. Here are the numbers using sed[1]
instead:

  $ time __gitcomp_nl "$refs"
  real    0m0.100s
  user    0m0.084s
  sys     0m0.016s

So a little slower, but probably acceptable. We could maybe do the same
trick on the output side (although it is a little trickier there,
because we need it in a bash array). Of course, this is Linux; the fork
for sed is way more expensive on some systems.

Still, I'd be curious to see it with the callers (e.g., __git_refs)
doing their own quoting. I'd worry that it would become a maintenance
headache, but perhaps we don't have that many lists we feed (there are a
lot of calls to gitcomp_nl, but they are mostly feeding __git_refs).

-Peff

[1] For reference, that patch is:

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1fc43f7..5ff3742 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -225,16 +225,15 @@ __git_quote()
 fi
 fi
 
-# Quotes each element of an IFS-delimited list for shell reuse
+# Quotes each element of a newline-delimited list for shell reuse
 __git_quote()
 {
-	local i
-	local delim
-	for i in $1; do
-		local quoted=${i//\'/\'\\\'\'}
-		printf "${delim:+$IFS}'%s'" "$quoted"
-		delim=t
-	done
+	echo "$1" |
+	sed "
+	  s/'/'\\\\''/g
+	  s/^/'/
+	  s/$/'/
+	"
 }
 
 # Generates completion reply with compgen, appending a space to possible

  reply	other threads:[~2012-09-27  6:43 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-20  2:15 [PATCH] completion: fix shell expansion of items Felipe Contreras
2012-09-20  1:46 ` Jeff King
2012-09-20 16:52   ` Junio C Hamano
2012-09-20 18:11   ` SZEDER Gábor
2012-09-20 18:21     ` Jeff King
2012-09-20 19:38       ` Felipe Contreras
2012-09-25  4:31     ` [PATCH] Revert "completion: fix shell expansion of items" Jeff King
2012-09-25 16:03       ` Junio C Hamano
2012-09-25 22:37       ` SZEDER Gábor
2012-09-25 23:28         ` Junio C Hamano
2012-09-26 21:46         ` Jeff King
2012-09-26 21:47           ` [PATCH 1/3] t9902: add a few basic completion tests Jeff King
2012-09-26 21:51           ` [PATCH 2/3] t9902: add completion tests for "odd" filenames Jeff King
2012-09-26 21:51           ` [PATCH 3/3] completion: improve shell expansion of items Jeff King
2012-09-26 21:57             ` [PATCH 4/3] completion: quote completions we find Jeff King
2012-09-27 21:40               ` SZEDER Gábor
2012-09-27 22:31                 ` Junio C Hamano
2012-09-27 22:58                   ` SZEDER Gábor
2012-09-27  0:37             ` [PATCH 3/3] completion: improve shell expansion of items SZEDER Gábor
2012-09-27  6:28               ` Jeff King
2012-09-27  6:43                 ` Jeff King [this message]
2012-09-27 19:48                   ` Jeff King
2012-09-28 10:05                   ` SZEDER Gábor
2012-09-28 10:09                     ` [PATCH 1/5] completion: fix non-critical bugs in __gitcomp() tests SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 2/5] completion: fix args of run_completion() test helper SZEDER Gábor
2012-09-28 18:04                         ` Junio C Hamano
2012-09-28 18:38                           ` SZEDER Gábor
2012-09-28 19:23                             ` Junio C Hamano
2012-09-28 19:30                               ` Jeff King
2012-09-28 19:49                                 ` Junio C Hamano
2012-09-28 19:55                                   ` Jeff King
2012-09-28 20:28                               ` SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 3/5] completion: add tests for the __gitcomp_nl() completion helper function SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 4/5] completion: test __gitcomp() and __gitcomp_nl() with expandable words SZEDER Gábor
2012-09-28 10:09                       ` [POC PATCH 5/5] completion: avoid compgen to fix expansion issues in __gitcomp_nl() SZEDER Gábor
2012-09-28 15:08                         ` SZEDER Gábor
2012-09-28 15:46                           ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20120927064338.GA4789@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder@ira.uka.de \
    /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://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).