fetch: avoid second connectivity check if we already have all objects
commitcaff8b73402d4b5edb2c6c755506c5a90351b69a
authorPatrick Steinhardt <ps@pks.im>
Wed, 1 Sep 2021 13:10:06 +0000 (1 15:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Sep 2021 19:43:56 +0000 (1 12:43 -0700)
treefce9c6660664c007dd5e56d86a1ed4fc6ff757e1
parent1c7d1ab6f4a79e44406f304ec01b0a143dae9abb
fetch: avoid second connectivity check if we already have all objects

When fetching refs, we are doing two connectivity checks:

    - The first one is done such that we can skip fetching refs in the
      case where we already have all objects referenced by the updated
      set of refs.

    - The second one verifies that we have all objects after we have
      fetched objects.

We always execute both connectivity checks, but this is wasteful in case
the first connectivity check already notices that we have all objects
locally available.

Skip the second connectivity check in case we already had all objects
available. This gives us a nice speedup when doing a mirror-fetch in a
repository with about 2.3M refs where the fetching repo already has all
objects:

    Benchmark #1: HEAD~: git-fetch
      Time (mean ± σ):     30.025 s ±  0.081 s    [User: 27.070 s, System: 4.933 s]
      Range (min … max):   29.900 s … 30.111 s    5 runs

    Benchmark #2: HEAD: git-fetch
      Time (mean ± σ):     25.574 s ±  0.177 s    [User: 22.855 s, System: 4.683 s]
      Range (min … max):   25.399 s … 25.765 s    5 runs

    Summary
      'HEAD: git-fetch' ran
        1.17 ± 0.01 times faster than 'HEAD~: git-fetch'

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