All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: David Mandelberg <david@mandelberg.org>
Cc: phillip.wood@dunelm.org.uk,
	David Mandelberg via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Jacob Keller <jacob.keller@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 3/3] completion: fix bugs with slashes in remote names
Date: Mon, 3 Mar 2025 20:33:54 +0100	[thread overview]
Message-ID: <Z8YEIo28bLS+t+20@szeder.dev> (raw)
In-Reply-To: <2323bb52-f43d-4f40-8955-4c648677a93e@mandelberg.org>

On Sun, Mar 02, 2025 at 03:34:07PM -0500, David Mandelberg wrote:
> Op 2025-03-02 om 09:17 schreef Phillip Wood:
> > Hi David
> > 
> > On 02/03/2025 07:45, David Mandelberg via GitGitGadget wrote:
> > > From: David Mandelberg <david@mandelberg.org>
> > > 
> > > Previously, some calls to for-each-ref passed fixed numbers of path
> > > components to strip from refs, assuming that remote names had no slashes
> > > in them. This made completions like:
> > > 
> > > git push github/dseomn :com<Tab>
> > > 
> > > Result in:
> > > 
> > > git push github/dseomn :dseomn/completion-remote-slash
> > > 
> > > With this patch, it instead results in:
> > > 
> > > git push github/dseomn :completion-remote-slash
> > 
> > This sounds like a useful improvement and I like the idea, but I think
> > running "git for-each-ref" once for each remote is not going to scale
> > very well for people who have a lot of remotes. I think it would be
> > better to try and strip "refs/remote/$remote/" outside of "git for-each-
> > ref". I've not tested it but I think something like
> 
> Good point, I hadn't thought of that. Do you have a rough estimate of what
> "a lot of remotes" is? 100ish, maybe?

5.

In Git for Windows fork()-ing subshells and fork()+exec()-ing
processes is rather costly, about an order of magnitude slower than on
Linux.  The rough equivalent of the body of your loop, with two
subshells and a git process:

  time { a=$(echo 1) ; b=$(echo 2) ; git for-each-ref >/dev/null ; }

takes on average 0.17s on a windows box I have access to (with fully
packed refs, and merely 4 refs in total).  So guess at about 4-5
remotes it would take over a second to react to my TABs...

I would rather try to go in the opposite direction to see whether 'git
for-each-ref' could be taught to strip the "refs/remote/$remote/"
prefix with a format specifier option like '%(refname:strip=remote)'.

That would surely be faster than any shell filtering we might come up
with, and would also save us from the trouble of escaping glob and/or
regex metacharacters for shell/sed pattern matching.

> I'd like to do some testing to get
> actual performance numbers before trying to optimize this, because I think
> the optimization has some drawbacks, see below.
> 
> If optimization is needed, another approach is to parallelize the forks:
> 
> {
> 	local fer_pids=
> 	for ...
> 	do
> 		__git for-each-ref ... &
> 		fer_pids="$fer_pids $!"
> 	done
> 	test -z "$fer_pids" || wait $fer_pids
> } | sort | uniq -u
> 
> That might cause spikes in cpu/memory/disk usage that aren't ideal though.

Please don't do this, the completion script must not forkbomb the
system.


  parent reply	other threads:[~2025-03-03 19:33 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-02  7:45 [PATCH 0/3] completion: fix bugs with slashes in remote names David Mandelberg via GitGitGadget
2025-03-02  7:45 ` [PATCH 1/3] completion: add helper to escape strings for fnmatch David Mandelberg via GitGitGadget
2025-03-02  7:45 ` [PATCH 2/3] completion: add helper to count path components David Mandelberg via GitGitGadget
2025-03-02  7:45 ` [PATCH 3/3] completion: fix bugs with slashes in remote names David Mandelberg via GitGitGadget
2025-03-02 14:17   ` Phillip Wood
2025-03-02 20:34     ` David Mandelberg
2025-03-03 16:36       ` phillip.wood123
2025-03-03 19:19         ` David Mandelberg
2025-03-03 19:43           ` Todd Zullinger
2025-03-06 20:26             ` D. Ben Knoble
2025-03-06 20:24           ` D. Ben Knoble
2025-03-06 20:38             ` Junio C Hamano
2025-03-07 10:34             ` phillip.wood123
2025-03-07 21:46             ` David Mandelberg
2025-03-13 17:40               ` D. Ben Knoble
2025-03-13 20:19                 ` David Mandelberg
2025-03-03 20:29         ` Junio C Hamano
2025-03-03 19:33       ` SZEDER Gábor [this message]
2025-03-03 19:49         ` David Mandelberg
2025-03-06 20:46   ` Junio C Hamano
2025-03-07 20:11     ` David Mandelberg
2025-03-07 20:57       ` Junio C Hamano
2025-03-07 21:38         ` David Mandelberg
2025-03-07 21:45           ` Junio C Hamano
2025-03-05  0:07 ` [PATCH v2 0/2] " David Mandelberg
2025-03-05  0:08   ` [PATCH v2 1/2] completion: add helper to count path components David Mandelberg
2025-03-05  0:09   ` [PATCH v2 2/2] completion: fix bugs with slashes in remote names David Mandelberg
2025-03-05 20:50     ` David Mandelberg
2025-03-06 16:35       ` Phillip Wood
2025-03-06 17:12         ` David Mandelberg
2025-03-06 17:39           ` Phillip Wood
2025-03-14 19:40 ` [PATCH v3 0/2] " David Mandelberg
2025-03-14 19:41   ` [PATCH v3 1/2] completion: add helper to count path components David Mandelberg
2025-03-14 19:43   ` [PATCH v3 2/2] completion: fix bugs with slashes in remote names David Mandelberg
2025-03-14 22:18     ` Junio C Hamano
2025-03-14 22:37       ` David Mandelberg
2025-03-14 23:23         ` Junio C Hamano
2025-03-18 17:02           ` Phillip Wood
2025-03-18 17:27             ` Junio C Hamano
2025-03-23 21:04 ` [PATCH v4 0/2] " David Mandelberg
2025-03-23 21:05   ` [PATCH v4 1/2] completion: add helper to count path components David Mandelberg
2025-03-23 21:06   ` [PATCH v4 2/2] completion: fix bugs with slashes in remote names David Mandelberg
2025-04-08 14:18   ` [PATCH v4 0/2] " Phillip Wood
2025-04-08 18:55     ` David Mandelberg

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=Z8YEIo28bLS+t+20@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=david@mandelberg.org \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.