From: Derrick Stolee <derrickstolee@github.com>
To: Taylor Blau <me@ttaylorr.com>, git@vger.kernel.org
Cc: gitster@pobox.com
Subject: Re: [PATCH] builtin/show-ref.c: avoid over-iterating with --heads, --tags
Date: Fri, 3 Jun 2022 22:33:47 -0400 [thread overview]
Message-ID: <af32aefc-8184-94ff-fd80-76221dc313b4@github.com> (raw)
In-Reply-To: <3fa6932641f18d78156bbf60b1571383f2cb5046.1654293264.git.me@ttaylorr.com>
On 6/3/2022 5:55 PM, Taylor Blau wrote:
> When `show-ref` is combined with the `--heads` or `--tags` options, it
> can avoid iterating parts of a repository's references that it doesn't
> care about.
>
> But it doesn't take advantage of this potential optimization. When this
> command was introduced back in 358ddb62cf (Add "git show-ref" builtin
> command, 2006-09-15), `for_each_ref_in()` did exist. But since most
> repositories don't have many (any?) references that aren't branches or
> tags already, this makes little difference in practice.
...
> Nonetheless, in our synthetic example above, this provides a significant
> speed-up ("git" is roughly v2.36, "git.compile" is this patch):
>
> $ hyperfine -N 'git show-ref --heads' 'git.compile show-ref --heads'
> Benchmark 1: git show-ref --heads
> Time (mean ± σ): 49.9 ms ± 6.2 ms [User: 45.6 ms, System: 4.1 ms]
> Range (min … max): 46.1 ms … 73.6 ms 43 runs
>
> Benchmark 2: git.compile show-ref --heads
> Time (mean ± σ): 2.8 ms ± 0.4 ms [User: 1.4 ms, System: 1.2 ms]
> Range (min … max): 1.3 ms … 5.6 ms 957 runs
>
> Summary
> 'git.compile show-ref --heads' ran
> 18.03 ± 3.38 times faster than 'git show-ref --heads'
Excellent speedup.
> - for_each_ref(show_ref, NULL);
> + if (heads_only || tags_only) {
> + if (heads_only)
> + for_each_fullref_in("refs/heads/", show_ref, NULL);
> + if (tags_only)
> + for_each_fullref_in("refs/tags/", show_ref, NULL);
This looks a little silly if these were truly "only" (they
could not both be true), but indeed they could both be true
and the names are just slightly misleading.
Indeed, t1403-show-ref.sh tests all combinations of these
options.
> + } else {
> + for_each_ref(show_ref, NULL);
> + }
Thanks for finding this!
-Stolee
next prev parent reply other threads:[~2022-06-04 2:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-03 21:55 [PATCH] builtin/show-ref.c: avoid over-iterating with --heads, --tags Taylor Blau
2022-06-04 2:33 ` Derrick Stolee [this message]
2022-06-06 17:07 ` Junio C Hamano
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=af32aefc-8184-94ff-fd80-76221dc313b4@github.com \
--to=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
/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 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).