Skip to content

Commit bcec678

Browse files
pks-tttaylorr
authored andcommitted
receive-pack: only use visible refs for connectivity check
When serving a push, git-receive-pack(1) needs to verify that the packfile sent by the client contains all objects that are required by the updated references. This connectivity check works by marking all preexisting references as uninteresting and using the new reference tips as starting point for a graph walk. Marking all preexisting references as uninteresting can be a problem when it comes to performance. Git forges tend to do internal bookkeeping to keep alive sets of objects for internal use or make them easy to find via certain references. These references are typically hidden away from the user so that they are neither advertised nor writeable. At GitLab, we have one particular repository that contains a total of 7 million references, of which 6.8 million are indeed internal references. With the current connectivity check we are forced to load all these references in order to mark them as uninteresting, and this alone takes around 15 seconds to compute. We can optimize this by only taking into account the set of visible refs when marking objects as uninteresting. This means that we may now walk more objects until we hit any object that is marked as uninteresting. But it is rather unlikely that clients send objects that make large parts of objects reachable that have previously only ever been hidden, whereas the common case is to push incremental changes that build on top of the visible object graph. This provides a huge boost to performance in the mentioned repository, where the vast majority of its refs hidden. Pushing a new commit into this repo with `transfer.hideRefs` set up to hide 6.8 million of 7 refs as it is configured in Gitaly leads to a 4.5-fold speedup: Benchmark 1: main Time (mean ± σ): 30.977 s ± 0.157 s [User: 30.226 s, System: 1.083 s] Range (min … max): 30.796 s … 31.071 s 3 runs Benchmark 2: pks-connectivity-check-hide-refs Time (mean ± σ): 6.799 s ± 0.063 s [User: 6.803 s, System: 0.354 s] Range (min … max): 6.729 s … 6.850 s 3 runs Summary 'pks-connectivity-check-hide-refs' ran 4.56 ± 0.05 times faster than 'main' As we mostly go through the same codepaths even in the case where there are no hidden refs at all compared to the code before there is no change in performance when no refs are hidden: Benchmark 1: main Time (mean ± σ): 48.188 s ± 0.432 s [User: 49.326 s, System: 5.009 s] Range (min … max): 47.706 s … 48.539 s 3 runs Benchmark 2: pks-connectivity-check-hide-refs Time (mean ± σ): 48.027 s ± 0.500 s [User: 48.934 s, System: 5.025 s] Range (min … max): 47.504 s … 48.500 s 3 runs Summary 'pks-connectivity-check-hide-refs' ran 1.00 ± 0.01 times faster than 'main' Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 5ff36c9 commit bcec678

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

builtin/receive-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,8 @@ static void execute_commands(struct command *commands,
19291929
opt.err_fd = err_fd;
19301930
opt.progress = err_fd && !quiet;
19311931
opt.env = tmp_objdir_env(tmp_objdir);
1932+
opt.exclude_hidden_refs_section = "receive";
1933+
19321934
if (check_connected(iterate_receive_command_list, &data, &opt))
19331935
set_connectivity_errors(commands, si);
19341936

connected.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
100100
strvec_push(&rev_list.args, "--exclude-promisor-objects");
101101
if (!opt->is_deepening_fetch) {
102102
strvec_push(&rev_list.args, "--not");
103+
if (opt->exclude_hidden_refs_section)
104+
strvec_pushf(&rev_list.args, "--exclude-hidden=%s",
105+
opt->exclude_hidden_refs_section);
103106
strvec_push(&rev_list.args, "--all");
104107
}
105108
strvec_push(&rev_list.args, "--quiet");

connected.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ struct check_connected_options {
4646
* during a fetch.
4747
*/
4848
unsigned is_deepening_fetch : 1;
49+
50+
/*
51+
* If not NULL, use `--exclude-hidden=$section` to exclude all refs
52+
* hidden via the `$section.hideRefs` config from the set of
53+
* already-reachable refs.
54+
*/
55+
const char *exclude_hidden_refs_section;
4956
};
5057

5158
#define CHECK_CONNECTED_INIT { 0 }

0 commit comments

Comments
 (0)