]> git.ipfire.org Git - thirdparty/git.git/commit
fast-import: use writev(3p) to send cat-blob responses
authorPatrick Steinhardt <ps@pks.im>
Thu, 16 Jul 2026 07:52:23 +0000 (09:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jul 2026 20:59:13 +0000 (13:59 -0700)
commit740d24e5416182d45cecfdf5eaa1074ee6005ec1
treef0cdd6a566d05a78c510815bf63eb444c2e41959
parente4c19e50916a2ff8cc1f42d99a6bfd73bf29ca96
fast-import: use writev(3p) to send cat-blob responses

When answering a `cat-blob` command, `cat_blob()` issues three separate
calls to write(3p) on the cat-blob fd: one for the header line, one for
the full blob payload, and one for the trailing newline. Frontends like
git-filter-repo issue these commands in bulk, once per rewritten blob,
so the syscall overhead adds up.

Use `writev_in_full()` to send all three parts with a single syscall.

This can be benchmarked with the following setup:

    $ git cat-file --unordered --filter=object:type=blob
        --batch-check='cat-blob %(objectname)' --batch-all-objects >request
    $ git fast-import --cat-blob-fd=3 <request

Executing this with 100,000 objects in linux.git:

  Benchmark 1: HEAD~
    Time (mean ± σ):      1.320 s ±  0.003 s    [User: 1.154 s, System: 0.161 s]
    Range (min … max):    1.314 s …  1.324 s    10 runs

  Benchmark 2: HEAD
    Time (mean ± σ):      1.270 s ±  0.022 s    [User: 1.133 s, System: 0.132 s]
    Range (min … max):    1.209 s …  1.282 s    10 runs

  Summary
    HEAD ran
      1.04 ± 0.02 times faster than HEAD~

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c