From: "René Scharfe" <l.s.r@web.de>
To: Derrick Stolee <stolee@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
"Martin Ågren" <martin.agren@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH 08/10] name-rev: pre-size buffer in get_parent_name()
Date: Wed, 5 Feb 2020 16:16:54 +0100 [thread overview]
Message-ID: <ea3910e1-f1cb-8a3c-0e32-5c33eeeb8af6@web.de> (raw)
In-Reply-To: <9b98835d-d94c-19f5-42ba-d583a33306cc@gmail.com>
Am 05.02.20 um 04:19 schrieb Derrick Stolee:
> On 2/4/2020 4:24 PM, René Scharfe wrote:
>> We can calculate the size of new name easily and precisely. Open-code
>> the xstrfmt() calls and grow the buffers as needed before filling them.
>> This provides a surprisingly large benefit when working with the
>> Chromium repository; here are the numbers measured using hyperfine
>> before:
>>
>> Benchmark #1: ./git -C ../chromium/src name-rev --all
>> Time (mean ± σ): 5.822 s ± 0.013 s [User: 5.304 s, System: 0.516 s]
>> Range (min … max): 5.803 s … 5.837 s 10 runs
>>
>> ... and with this patch:
>>
>> Benchmark #1: ./git -C ../chromium/src name-rev --all
>> Time (mean ± σ): 1.527 s ± 0.003 s [User: 1.015 s, System: 0.511 s]
>> Range (min … max): 1.524 s … 1.535 s 10 runs
>
> Nice!
>
>> + if (name->generation > 0) {
>> + strbuf_grow(&sb, len +
>> + 1 + decimal_width(name->generation) +
>> + 1 + decimal_width(parent_number));
>
> Just curious: these strbuf_grow() calls are what _really_ improve the
> performance, right? If you dropped them, then can we expect the performance
> to be similar to the old code?
The replaced xstrfmt() is defined in strbuf.c and trivially wraps
xstrvfmt(), which in turn does:
struct strbuf buf = STRBUF_INIT;
strbuf_vaddf(&buf, fmt, ap);
return strbuf_detach(&buf, NULL);
And strbuf_addf() trivially wraps strbuf_vaddf(). So indeed, all
I did was to inline xstrfmt() and add the strbuf_grow() calls.
Their high impact shocked me a bit. vsnprintf(3) really doesn't seem
to like working with a buffer that is too small (when it's supposed to
just calculate how many bytes it would have needed), at least not in
the one from glibc 2.29.
>> + strbuf_addf(&sb, "%.*s~%d^%d", (int)len, name->tip_name,
>> + name->generation, parent_number);
>> + } else {
>> + strbuf_grow(&sb, len +
>> + 1 + decimal_width(parent_number));
>> + strbuf_addf(&sb, "%.*s^%d", (int)len, name->tip_name,
>> + parent_number);
>> + }
>> + return strbuf_detach(&sb, NULL);
>> }
>>
>> static void name_rev(struct commit *start_commit,
>> --
>> 2.25.0
>>
>
next prev parent reply other threads:[~2020-02-05 15:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 21:12 [PATCH 00/10] name-rev: improve memory usage René Scharfe
2020-02-04 21:14 ` [PATCH 01/10] name-rev: rewrite create_or_update_name() René Scharfe
2020-02-05 2:00 ` Derrick Stolee
2020-02-05 2:35 ` Taylor Blau
2020-02-05 16:45 ` Andrei Rybak
2020-02-05 16:47 ` René Scharfe
2020-02-04 21:15 ` [PATCH 02/10] name-rev: remove unused typedef René Scharfe
2020-02-04 21:16 ` [PATCH 03/10] name-rev: respect const qualifier René Scharfe
2020-02-04 21:17 ` [PATCH 04/10] name-rev: don't leak path copy in name_ref() René Scharfe
2020-02-05 14:35 ` Derrick Stolee
2020-02-04 21:20 ` [PATCH 05/10] name-rev: don't _peek() in create_or_update_name() René Scharfe
2020-02-04 21:22 ` [PATCH 06/10] name-rev: put struct rev_name into commit slab René Scharfe
2020-02-04 21:23 ` [PATCH 07/10] name-rev: factor out get_parent_name() René Scharfe
2020-02-04 21:24 ` [PATCH 08/10] name-rev: pre-size buffer in get_parent_name() René Scharfe
2020-02-05 3:19 ` Derrick Stolee
2020-02-05 15:16 ` René Scharfe [this message]
2020-02-04 21:25 ` [PATCH 09/10] name-rev: generate name strings only if they are better René Scharfe
2020-02-05 15:11 ` Derrick Stolee
2020-02-05 15:50 ` René Scharfe
2020-02-04 21:26 ` [PATCH 10/10] name-rev: release unused name strings René Scharfe
2020-02-05 15:19 ` Derrick Stolee
2020-02-05 3:28 ` [PATCH 00/10] name-rev: improve memory usage Derrick Stolee
2020-02-05 15:20 ` Derrick Stolee
2020-02-05 17:19 ` [PATCH 01/10 RESEND AUTHOR FIXED] name-rev: rewrite create_or_update_name() René Scharfe
2020-02-05 17:50 ` [PATCH 11/10] name-rev: sort tip names before applying René Scharfe
2020-02-05 18:23 ` Junio C Hamano
2020-02-05 18:55 ` René Scharfe
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=ea3910e1-f1cb-8a3c-0e32-5c33eeeb8af6@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=martin.agren@gmail.com \
--cc=stolee@gmail.com \
--cc=szeder.dev@gmail.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.
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).