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

Re: [PATCH 3/3] reftable/stack: avoid reloading the stack when already locked

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 23, 2026, 17:39 UTC
Message-ID
<CAOLa=ZQpeCKzQ3EVXQEhfxL1khUH0YD6_Kc1qDQhxoN926rsBw@mail.gmail.com>
In-Reply-To
<20260820075342.GA2761530@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 53 quoted lines
> On Wed, Aug 19, 2026 at 03:19:39PM +0200, Karthik Nayak wrote:
>
>> Benchmarking with a fixed, non-symbolic target OID shows a modest but
>> consistent ~1-2% improvement in clock time for `update-ref` across ref
>> counts ranging from 2,000 to 100,000.
>
> Interesting. I get ~25% speedup with this patch, doing this:
>
>   git init --ref-format=reftable
>   cp -a .git/reftable reftable.orig
>   seq -f "create refs/tags/foo-%g $blob" 50000 >input
>   hyperfine -p 'rm -rf .git/reftable; cp -a reftable.orig .git/reftable' \
>            -L v old,new \
> 	   './git.{v} update-ref --stdin <input'
>
> (where git.old and git.new are builds before and after your series).
> With 50,000 refs I get:
>
>   Benchmark 1: ./git.old update-ref --stdin <input
>     Time (mean ± σ):     125.8 ms ±   4.4 ms    [User: 91.2 ms, System: 34.5 ms]
>     Range (min … max):   121.0 ms … 135.2 ms    21 runs
>
>   Benchmark 2: ./git.new update-ref --stdin <input
>     Time (mean ± σ):     100.4 ms ±   3.1 ms    [User: 90.9 ms, System: 9.4 ms]
>     Range (min … max):    95.0 ms … 106.0 ms    29 runs
>
>   Summary
>     ./git.new update-ref --stdin <input ran
>       1.25 ± 0.06 times faster than ./git.old update-ref --stdin <input
>
> And it seems to scale down linearly. With 10,000 it's:
>
>   Benchmark 1: ./git.old update-ref --stdin <input
>     Time (mean ± σ):      24.2 ms ±   1.4 ms    [User: 17.1 ms, System: 7.1 ms]
>     Range (min … max):    22.6 ms …  32.8 ms    83 runs
>
>   Benchmark 2: ./git.new update-ref --stdin <input
>     Time (mean ± σ):      19.2 ms ±   1.0 ms    [User: 16.9 ms, System: 2.4 ms]
>     Range (min … max):    17.9 ms …  25.8 ms    135 runs
>
>   Summary
>     ./git.new update-ref --stdin <input ran
>       1.26 ± 0.10 times faster than ./git.old update-ref --stdin <input
>
> So 1/5 as much work took 1/5 as much time, but we still saved 25% of the
> relative time with the patch.
>
> I'm a little curious why we such get different numbers, but it may not
> be worth digging too deep. Avoiding unnecessary syscalls seems worth it
> to me regardless, as they can sometimes be more expensive you expect
> (say, on a networked filesystem).
>
> -Peff

I can reproduce your results locally too. I was a bit stumbled why, I was using a modified version of our benchmarks repository [1], which was using a fixed static target.

The difference was I was updating 'refs/heads/*' and your script does 'refs/tags/*'. The difference is in `should_write_log()`, where for LOG_REFS_NORMAL and 'refs/heads/*' we shortcut to creating the logs. While for tags, we do a check to see reflog already exists. This causes a stack reload (before my patches). This shows the significant difference in our benchmarks.

Funnily, I use 'refs/tags/*' for strace, so you do see the diff there. Will modify my commit message to reflect the benchmark :)

[1]: https://gitlab.com/gitlab-org/data-access/git/benchmarks/
Previous: Jeff KingNext: Jeff King
Message 16 of 17 in “reftable/stack: avoid reloading the stack when locked”
  1. 0/3 reftable/stack: avoid reloading the stack when lockedKarthik Nayak, Aug 19, 2026
  2. 1/3 reftable/stack: remove `REFTABLE_STACK_NEW_ADDITION_RELOAD`Karthik Nayak, Aug 19, 2026
  3. Justin ToblerAug 19, 2026
  4. Karthik NayakAug 20, 2026
  5. Patrick SteinhardtAug 20, 2026
  6. Karthik NayakAug 20, 2026
  7. Karthik NayakAug 20, 2026
  8. 2/3 reftable/stack: move list lock to `struct reftable_stack`Karthik Nayak, Aug 19, 2026
  9. Justin ToblerAug 19, 2026
  10. Junio C HamanoAug 19, 2026
  11. Karthik NayakAug 23, 2026
  12. 3/3 reftable/stack: avoid reloading the stack when already lockedKarthik Nayak, Aug 19, 2026
  13. Justin ToblerAug 19, 2026
  14. Karthik NayakAug 23, 2026
  15. Jeff KingAug 20, 2026
  16. Karthik NayakAug 23, 2026
  17. Jeff KingAug 24, 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.