Skip to content

Commit be18153

Browse files
jacobvosmaergitster
authored andcommitted
builtin/pack-objects.c: avoid iterating all refs
In git-pack-objects, we iterate over all the tags if the --include-tag option is passed on the command line. For some reason this uses for_each_ref which is expensive if the repo has many refs. We should use for_each_tag_ref instead. Because the add_ref_tag callback will now only visit tags we simplified it a bit. The motivation for this change is that we observed performance issues with a repository on gitlab.com that has 500,000 refs but only 2,000 tags. The fetch traffic on that repo is dominated by CI, and when we changed CI to fetch with 'git fetch --no-tags' we saw a dramatic change in the CPU profile of git-pack-objects. This lead us to this particular ref walk. More details in: https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/746#note_483546598 Signed-off-by: Jacob Vosmaer <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66e871b commit be18153

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,13 +2803,11 @@ static void add_tag_chain(const struct object_id *oid)
28032803
}
28042804
}
28052805

2806-
static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data)
2806+
static int add_ref_tag(const char *tag, const struct object_id *oid, int flag, void *cb_data)
28072807
{
28082808
struct object_id peeled;
28092809

2810-
if (starts_with(path, "refs/tags/") && /* is a tag? */
2811-
!peel_ref(path, &peeled) && /* peelable? */
2812-
obj_is_packed(&peeled)) /* object packed? */
2810+
if (!peel_ref(tag, &peeled) && obj_is_packed(&peeled))
28132811
add_tag_chain(oid);
28142812
return 0;
28152813
}
@@ -3740,7 +3738,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
37403738
}
37413739
cleanup_preferred_base();
37423740
if (include_tag && nr_result)
3743-
for_each_ref(add_ref_tag, NULL);
3741+
for_each_tag_ref(add_ref_tag, NULL);
37443742
stop_progress(&progress_state);
37453743
trace2_region_leave("pack-objects", "enumerate-objects",
37463744
the_repository);

0 commit comments

Comments
 (0)