git/refs
Patrick Steinhardt 0a7b38707d refs/files-backend: optimize reading of symbolic refs
When reading references via `files_read_raw_ref()` we always consult
both the loose reference, and if that wasn't found, we also consult the
packed-refs file. While this makes sense to read a generic reference, it
is wasteful in the case where we only care about symbolic references:
the packed-refs backend does not support them, and thus it cannot ever
return one for us.

Special-case reading of symbolic references for the files backend such
that we always skip asking the packed-refs backend.

We use `refs_read_symbolic_ref()` extensively to determine whether we
need to skip updating local symbolic references during a fetch, which is
why the change results in a significant speedup when doing fetches in
repositories with huge numbers of references. The following benchmark
executes a mirror-fetch in a repository with about 2 million references
via `git fetch --prune --no-write-fetch-head +refs/*:refs/*`:

    Benchmark 1: HEAD~
      Time (mean ± σ):     68.372 s ±  2.344 s    [User: 65.629 s, System: 8.786 s]
      Range (min … max):   65.745 s … 70.246 s    3 runs

    Benchmark 2: HEAD
      Time (mean ± σ):     60.259 s ±  0.343 s    [User: 61.019 s, System: 7.245 s]
      Range (min … max):   60.003 s … 60.649 s    3 runs

    Summary
      'HEAD' ran
        1.13 ± 0.04 times faster than 'HEAD~'

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-03-01 10:13:46 -08:00
..
debug.c refs: add ability for backends to special-case reading of symbolic refs 2022-03-01 10:13:46 -08:00
files-backend.c refs/files-backend: optimize reading of symbolic refs 2022-03-01 10:13:46 -08:00
iterator.c use CALLOC_ARRAY 2021-03-13 16:00:09 -08:00
packed-backend.c refs: add ability for backends to special-case reading of symbolic refs 2022-03-01 10:13:46 -08:00
packed-backend.h Merge branch 'ps/avoid-unnecessary-hook-invocation-with-packed-refs' 2022-02-18 13:53:27 -08:00
ref-cache.c Merge branch 'jt/no-abuse-alternate-odb-for-submodules' 2021-10-25 16:06:56 -07:00
ref-cache.h Merge branch 'jt/no-abuse-alternate-odb-for-submodules' 2021-10-25 16:06:56 -07:00
refs-internal.h refs: add ability for backends to special-case reading of symbolic refs 2022-03-01 10:13:46 -08:00