git-commit-vandalism/refs
Michael Haggerty 8ec617c80c files-backend: cheapen refname_available check when locking refs
When locking references in preparation for updating them, we need to
check that none of the newly added references D/F conflict with
existing references (e.g., we don't allow `refs/foo` to be added if
`refs/foo/bar` already exists, or vice versa).

Prior to 524a9fdb51 (refs_verify_refname_available(): use function in
more places, 2017-04-16), conflicts with existing loose references
were checked by looking directly in the filesystem, and then conflicts
with existing packed references were checked by running
`verify_refname_available_dir()` against the packed-refs cache.

But that commit changed the final check to call
`refs_verify_refname_available()` against the *whole* files ref-store,
including both loose and packed references, with the following
comment:

> This means that those callsites now check for conflicts with all
> references rather than just packed refs, but the performance cost
> shouldn't be significant (and will be regained later).

That comment turned out to be too sanguine. User s@kazlauskas.me
reported that fetches involving a very large number of references in
neighboring directories were slowed down by that change.

The problem is that when fetching, each reference is updated
individually, within its own reference transaction. This is done
because some reference updates might succeed even though others fail.
But every time a reference update transaction is finished,
`clear_loose_ref_cache()` is called. So when it is time to update the
next reference, part of the loose ref cache has to be repopulated for
the `refs_verify_refname_available()` call. If the references are all
in neighboring directories, then the cost of repopulating the
reference cache increases with the number of references, resulting in
O(N²) effort.

The comment above also claims that the performance cost "will be
regained later". The idea was that once the packed-refs were finished
being split out into a separate ref-store, we could limit the
`refs_verify_refname_available()` call to the packed references again.
That is what we do now.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-08-17 14:32:23 -07:00
..
files-backend.c files-backend: cheapen refname_available check when locking refs 2017-08-17 14:32:23 -07:00
iterator.c prefix_ref_iterator: don't trim too much 2017-05-23 14:29:52 +09:00
packed-backend.c packed_ref_store: handle a packed-refs file that is a symlink 2017-07-27 10:19:56 -07:00
packed-backend.h packed_refs_unlock(), packed_refs_is_locked(): new functions 2017-06-23 13:27:33 -07:00
ref-cache.c cache_ref_iterator_begin(): avoid priming unneeded directories 2017-05-24 21:21:21 +09:00
ref-cache.h create_ref_entry(): remove check_name option 2017-05-23 14:29:56 +09:00
refs-internal.h packed_ref_store: make class into a subclass of ref_store 2017-06-23 13:27:33 -07:00