From: Phillip Wood <phillip.wood123@gmail.com>
To: Jeff King <peff@peff.net>,
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, vdye@github.com, me@ttaylorr.com,
mjcheetham@outlook.com, Derrick Stolee <derrickstolee@github.com>
Subject: Re: [PATCH 2/2] for-each-ref: add --count-matches option
Date: Wed, 28 Jun 2023 14:12:38 +0100 [thread overview]
Message-ID: <776c3682-d2eb-d2d7-3ea8-4a7db8cd7842@gmail.com> (raw)
In-Reply-To: <f6fd39bc-65d4-76e3-94b4-9163194c89dd@gmail.com>
On 27/06/2023 11:05, Phillip Wood wrote:
> On 27/06/2023 08:30, Jeff King wrote:
>> I don't think this is a very realistic perf test, because for-each-ref
>> is doing a bunch of work to generate its default format, only to have
>> "wc" throw most of it away. Doing:
>>
>> git for-each-ref --format='%(refname)' | wc -l
>
> That's a good point. I wondered if using a short fixed format string was
> even better so I tried
>
> git init test
> cd test
> git commit --allow-empty -m initial
> seq 0 100000 | sed "s:\(.*\):create refs/heads/some-prefix/\1 $(git
> rev-parse HEAD):" | git update-ref --stdin
> git pack-refs --all
> hyperfine -L fmt "","--format=%\(refname\)","--format=x" 'git
> for-each-ref {fmt} refs/heads/ | wc -l'
>
> Which gives
> [...]
> Summary
> git for-each-ref --format=x refs/heads/ | wc -l ran
> 1.05 ± 0.01 times faster than git for-each-ref
> --format=%\(refname\) refs/heads/ | wc -l
> 18.25 ± 0.20 times faster than git for-each-ref refs/heads/ | wc -l
> [...]
> I'm a bit suspicious of the massive speed up I'm seeing by avoiding the
> default format but it appears to be repeatable.
Having seen Peff's mail [1] I realized that my test repo above is
looking up the commit from a loose object. If I repack the repository
then the default format is still slower than using "--format=%(refname)"
but is much more competitive.
$ git repack -a
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Writing objects: 100% (2/2), done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
$ hyperfine -L fmt "","--format=%\(refname\)","--format=x" 'git
for-each-ref {fmt} refs/heads/ | wc'
Benchmark 1: git for-each-ref refs/heads/ | wc -l
Time (mean ± σ): 111.4 ms ± 1.4 ms [User: 96.9 ms, System:
19.6 ms]
Range (min … max): 109.6 ms … 115.1 ms 25 runs
Benchmark 2: git for-each-ref --format=%\(refname\) refs/heads/ | wc -l
Time (mean ± σ): 66.7 ms ± 0.7 ms [User: 59.5 ms, System:
9.5 ms]
Range (min … max): 65.6 ms … 68.2 ms 42 runs
Benchmark 3: git for-each-ref --format=x refs/heads/ | wc -l
Time (mean ± σ): 63.4 ms ± 0.7 ms [User: 56.3 ms, System:
8.0 ms]
Range (min … max): 61.9 ms … 65.1 ms 44 runs
Summary
git for-each-ref --format=x refs/heads/ | wc -l ran
1.05 ± 0.02 times faster than git for-each-ref
--format=%\(refname\) refs/heads/ | wc -l
1.76 ± 0.03 times faster than git for-each-ref refs/heads/ | wc -l
So it seems most of the slowdown I was seeing yesterday was due it
looking up a loose object. I'm surprised repacking makes such a
difference in a repository that only contains two objects.
Best Wishes
Phillip
[1]
https://lore.kernel.org/git/20230627195900.GC1280909@coredump.intra.peff.net
next prev parent reply other threads:[~2023-06-28 13:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 15:09 [PATCH 0/2] [RFC] for-each-ref: add --count-matches mode Derrick Stolee via GitGitGadget
2023-06-26 15:09 ` [PATCH 1/2] for-each-ref: extract ref output loop Derrick Stolee via GitGitGadget
2023-06-26 15:09 ` [PATCH 2/2] for-each-ref: add --count-matches option Derrick Stolee via GitGitGadget
2023-06-26 16:14 ` Junio C Hamano
2023-06-27 7:30 ` Jeff King
2023-06-27 10:05 ` Phillip Wood
2023-06-27 18:22 ` Junio C Hamano
2023-06-27 19:59 ` Jeff King
2023-06-28 13:12 ` Phillip Wood [this message]
2023-06-28 17:08 ` Junio C Hamano
2023-07-11 14:48 ` René Scharfe
2023-07-10 16:51 ` Derrick Stolee
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=776c3682-d2eb-d2d7-3ea8-4a7db8cd7842@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
--cc=mjcheetham@outlook.com \
--cc=peff@peff.net \
--cc=phillip.wood@dunelm.org.uk \
--cc=vdye@github.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).