git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] hex: add and use strbuf_add_oid_hex()

From
Jeff King <peff@peff.net>
Date
May 13, 2026, 16:01 UTC
Message-ID
<20260513160155.GA103037@coredump.intra.peff.net>
In-Reply-To
<183aa0fd-d455-4ec9-9c42-d511fac8b3e4@web.de>
On Wed, May 13, 2026 at 05:49:11PM +0200, René Scharfe wrote:
Show 16 quoted lines
> 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.

I think this is worth doing solely for removing more instances of global buffers, though.

-Peff
Previous: René ScharfeNext: René Scharfe
Message 2 of 3 in “hex: add and use strbuf_add_oid_hex()”
  1. hex: add and use strbuf_add_oid_hex()René Scharfe, May 13, 2026
  2. Jeff KingMay 13, 2026
  3. René ScharfeMay 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.