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

Re: [PATCH v2] packed-refs: use `fwrite()` when passing refs verbatim

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 6, 2026, 09:36 UTC
Message-ID
<CAOLa=ZR12Xc2ZV2T4q+HZTa4TfeO8G7GiabZr3EYdrG-n6YA8A@mail.gmail.com>
In-Reply-To
<87zewsf13b.fsf@dev.null.iotcl.com.invalid>
Toon Claes <toon@iotcl.com> writes:
Show 17 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> The `write_with_updates()` function uses a `struct ref_iterator` to
>> iterate over all refs to write to the temporary packed-refs file. It
>> receives the iterator from `packed_ref_iterator_begin()` which takes a
>> snapshot of the 'packed-refs' file.
>>
>> While writing to the new packed-refs file, writes are routed via
>> `write_packed_entry()` which uses `fprintf()`. Even for references which
>> haven't changed, we use the same mechanism. Instead, let's track the
>> position of unchanged references in the snapshot iterator and directly
>> use `fwrite()`.
>>
>> With this, any sanitation which was happening as a side of reformatting
>
> s/side/side effect/ ?
>
That's probably better.
Show 32 quoted lines
>> is now lost. But that was never the job of this section of the code,
>> since the main intention is to simply rewrite the remaining refs post
>> deletion of the selective few.
>
> Agreed.
>
>>
>> This removes the unnecessary formatting operation involved. We can see a
>> consistent ~20% performance improvement when deleting from packed
>> references.
>>
>> Benchmark 1: update-ref: delete ref (refcount = 100000, revision = master)
>>   Time (mean ± σ):      28.7 ms ±   1.7 ms    [User: 22.5 ms, System: 5.9 ms]
>>   Range (min … max):    26.7 ms …  33.3 ms    46 runs
>>
>> Benchmark 2: update-ref: delete ref (refcount = 100000, revision = b4/kn-speedup-packed-refs)
>>   Time (mean ± σ):      23.8 ms ±   1.2 ms    [User: 17.5 ms, System: 6.0 ms]
>>   Range (min … max):    22.1 ms …  27.7 ms    56 runs
>>
>> Summary
>>   update-ref: delete ref (refcount = 100000, revision = b4/kn-speedup-packed-refs) ran
>>     1.21 ± 0.09 times faster than update-ref: delete ref (refformat = files, refcount = 100000, revision = master)
>>
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>> Changes in v2:
>> - Instead of using the existing function, introduce a new
>>   `write_packed_entry_raw()`.
>> - Modify the commit to also note that we lose sanitization.
>
> s/commit/commit message/
>
This doesn't go into the commit itself, so I'll leave it as is.
Show 7 quoted lines
>> - Link to v1: https://patch.msgid.link/20260930-kn-speedup-packed-refs-v1-1-111cd03d9b0e@gmail.com
>
> Okay, I'm okay with this version.
>
> --
> Laters,
> Toon
Thanks for the review.
Previous: Toon ClaesNext: Karthik Nayak
Message 6 of 16 in “packed-refs: use `fwrite()` when passing refs verbatim”
  1. packed-refs: use `fwrite()` when passing refs verbatimKarthik Nayak, Sep 30, 2026
  2. Toon ClaesOct 1, 2026
  3. Karthik NayakOct 2, 2026
  4. packed-refs: use `fwrite()` when passing refs verbatimKarthik Nayak, Oct 2, 2026
  5. Toon ClaesOct 5, 2026
  6. Karthik NayakOct 6, 2026
  7. packed-refs: use `fwrite()` when passing refs verbatimKarthik Nayak, Oct 6, 2026
  8. Patrick SteinhardtOct 6, 2026
  9. Karthik NayakOct 6, 2026
  10. Patrick SteinhardtOct 7, 2026
  11. Karthik NayakOct 7, 2026
  12. Junio C HamanoOct 6, 2026
  13. Karthik NayakOct 6, 2026
  14. packed-refs: use `fwrite()` when passing refs verbatimKarthik Nayak, Oct 7, 2026
  15. Patrick SteinhardtOct 7, 2026
  16. Toon ClaesOct 8, 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.