Git development
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] hex: add and use strbuf_add_oid_hex()
Date: Wed, 13 May 2026 18:55:47 +0200	[thread overview]
Message-ID: <a427dd4d-773c-45e4-87a7-3adb6f04dfb3@web.de> (raw)
In-Reply-To: <20260513160155.GA103037@coredump.intra.peff.net>

On 5/13/26 6:01 PM, Jeff King wrote:
> On Wed, May 13, 2026 at 05:49:11PM +0200, René Scharfe wrote:
> 
>> Add a function for adding the full hexadecimal hash value of an object
>> ID to a strbuf.  It's thread-safe and slightly more efficient than using
>> strbuf_addstr() with oid_to_hex() because it doesn't have to determine
>> the length of the string or copy it from the intermediate static buffer.
>>
>> Add and apply a semantic patch to use it throughout the code base.
>>
>> I get a tiny speedup for git log showing a single hash per commit:
>>
>> Benchmark 1: ./git_main log --format=%H
>>   Time (mean ± σ):      91.2 ms ±   0.7 ms    [User: 51.9 ms, System: 38.6 ms]
>>   Range (min … max):    89.8 ms …  92.6 ms    31 runs
>>
>> Benchmark 2: ./git log --format=%H
>>   Time (mean ± σ):      90.5 ms ±   0.7 ms    [User: 51.0 ms, System: 38.8 ms]
>>   Range (min … max):    89.2 ms …  92.3 ms    32 runs
> 
> Probably the most extreme benchmark would be:
> 
>   git cat-file --batch-all-objects --batch-check='%(objectname)'
> 
> which is really just dumping the oids from packfiles. I got ~3% speedup,
> though like yours it's within the run-to-run noise.

Hmm, should've lead with that; on an Apple M1:

Benchmark 1: ./git_main cat-file --batch-all-objects --batch-check='%(objectname)'
  Time (mean ± σ):     117.9 ms ±   0.2 ms    [User: 111.3 ms, System: 5.6 ms]
  Range (min … max):   117.5 ms … 118.5 ms    24 runs

Benchmark 2: ./git cat-file --batch-all-objects --batch-check='%(objectname)'
  Time (mean ± σ):     109.9 ms ±   0.2 ms    [User: 103.2 ms, System: 5.6 ms]
  Range (min … max):   109.5 ms … 110.8 ms    26 runs

Summary
  ./git cat-file --batch-all-objects --batch-check='%(objectname)' ran
    1.07 ± 0.00 times faster than ./git_main cat-file --batch-all-objects --batch-check='%(objectname)'

... and on an M5:

Benchmark 1: ./git_main cat-file --batch-all-objects --batch-check='%(objectname)'
  Time (mean ± σ):      76.8 ms ±   1.9 ms    [User: 73.0 ms, System: 3.2 ms]
  Range (min … max):    73.7 ms …  80.7 ms    38 runs

Benchmark 2: ./git cat-file --batch-all-objects --batch-check='%(objectname)'
  Time (mean ± σ):      70.8 ms ±   1.0 ms    [User: 66.9 ms, System: 3.3 ms]
  Range (min … max):    69.4 ms …  73.7 ms    41 runs

Summary
  ./git cat-file --batch-all-objects --batch-check='%(objectname)' ran
    1.08 ± 0.03 times faster than ./git_main cat-file --batch-all-objects --batch-check='%(objectname)'‚

René


      reply	other threads:[~2026-05-13 16:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 15:49 [PATCH] hex: add and use strbuf_add_oid_hex() René Scharfe
2026-05-13 16:01 ` Jeff King
2026-05-13 16:55   ` René Scharfe [this message]

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=a427dd4d-773c-45e4-87a7-3adb6f04dfb3@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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