Skip to content

fetch: Stop writing FETCH_HEAD

Patrick Steinhardt requested to merge pks-git-stop-writing-fetch-head into master

When fetching into a repository, git-fetch(1) by default writes the FETCH_HEAD file containing all references which have been updated. While this isn't much of a problem in "normal-sized" repositories, the file may easily be hundreds of megabytes in size when mirror-fetching from repositories with millions of references. Given that we ultimately don't use that file anywhere this is a big waste of resources.

In "www-gitlab-com", the FETCH_HEAD file is about 379MB in size after performing a mirror-fetch against another replica. The following shows the difference with and without writing FETCH_HEAD:

Benchmark 1: git fetch replica refs/*:refs/*
  Time (mean ± σ):     28.292 s ±  0.122 s    [User: 25.561 s, System: 3.787 s]
  Range (min … max):   28.159 s … 28.398 s    3 runs

Benchmark 2: git fetch --no-write-fetch-head replica refs/*:refs/*
  Time (mean ± σ):     27.820 s ±  0.064 s    [User: 25.068 s, System: 3.650 s]
  Range (min … max):   27.758 s … 27.885 s    3 runs

Summary
  'git fetch --no-write-fetch-head replica refs/*:refs/*' ran
    1.02 ± 0.00 times faster than 'git fetch replica refs/*:refs/*'

While the speed improvement is surprisingly small, it is still the right thing to do.

Changelog: changed

Part of https://gitlab.com/gitlab-org/gitaly/-/issues/2436

Merge request reports