threads / discuss / 49598

commit-graph is cool (overcoming add_missing_tags() perf issues)

Subject: commit-graph is cool (overcoming add_missing_tags() perf issues)

## tl;dr

7 messages between Oct 17, 2018 and Oct 31, 2018.

replies: 6people: 4as markdown or json

Elijah Newren· Oct 17, 2018, 18:00 UTC · lore
Hi,
Just wanted to give a shout-out for the commit-graph work and how
impressive it is.  I had an internal report from a user that git
pushes containing only one new tiny commit were taking over a minute
(in a moderate size repo with good network connectivity). After
digging for a while, I noticed three unusual things about the repo[1]:
  * he had push.followTags set to true
  * upstream repo had about 20k tags (despite only 55k commits)
  * his repo had an additional 2.5k tags, but none of these were in
    the history of the branches he was pushing and thus would not be
    included in any pushes.

Digging in, almost all the time was CPU-bound and spent in add_missing_tags()[2]. If I'm reading the code correctly, it appears that function loops over each tag, calling in_merge_bases_many() once per tag. Thus, for his case, we were potentially walking all of history of the main branch 2.5k times. That seemed rather suboptimal.

Before attempting to optimize, I decided to try out the commit-graph with a version of git from pu. While I expected a speed-up, I was a bit suprised that it was a factor of over 100; dropping the time for local dry-run push[2] to sub-second. A quick look suggests that commit-graph doesn't fix the fact that we call in_merge_bases_many() N times from add_missing_tags() and thus likely need to do N merge base computations, it just makes each of the N much faster. So, perhaps there's still another scaling issue we'll eventually need to address, but for now, I'm pretty excited about commit-graph.

(And in the mean time I gave the user a one-liner to nuke his local-only tags that I suspect he doesn't need.)

Thanks, Elijah

[1] lerna seems to scale horribly, especially when you suddenly transition dozens of web developers and even more independent repositories into a single large monorepo. Usage of lerna was thankfully ripped out at some point, but the crazy number of historical tags remain. Also, this user did a bunch of the filter-branch'ing to suck extra repos into the monorepo, likely involved somehow in the many extra tags he had.

[2] In fact, I still had timings of over a minute when adjusting the command to:
  git push --follow-tags --dry-run /PATH/TO/LOCAL-MIRROR $BRANCH
Derrick Stolee· Oct 17, 2018, 18:19 UTC · re: Elijah Newren · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On 10/17/2018 2:00 PM, Elijah Newren wrote:
Show 18 quoted lines
> Hi,
>
> Just wanted to give a shout-out for the commit-graph work and how
> impressive it is.  I had an internal report from a user that git
> pushes containing only one new tiny commit were taking over a minute
> (in a moderate size repo with good network connectivity). After
> digging for a while, I noticed three unusual things about the repo[1]:
>    * he had push.followTags set to true
>    * upstream repo had about 20k tags (despite only 55k commits)
>    * his repo had an additional 2.5k tags, but none of these were in
>      the history of the branches he was pushing and thus would not be
>      included in any pushes.
>
> Digging in, almost all the time was CPU-bound and spent in
> add_missing_tags()[2].  If I'm reading the code correctly, it appears
> that function loops over each tag, calling in_merge_bases_many() once
> per tag.  Thus, for his case, we were potentially walking all of
> history of the main branch 2.5k times.  That seemed rather suboptimal.

Thanks for the report. I made a note to inspect add_missing_tags() for more improvement in the future.

Show 9 quoted lines
> Before attempting to optimize, I decided to try out the commit-graph
> with a version of git from pu.  While I expected a speed-up, I was a
> bit suprised that it was a factor of over 100; dropping the time for
> local dry-run push[2] to sub-second.  A quick look suggests that
> commit-graph doesn't fix the fact that we call in_merge_bases_many() N
> times from add_missing_tags() and thus likely need to do N merge base
> computations, it just makes each of the N much faster.  So, perhaps
> there's still another scaling issue we'll eventually need to address,
> but for now, I'm pretty excited about commit-graph.
Without the commit-graph, you are getting a quadratic problem (N commits 
* T tags), but with the commit-graph you are also getting the benefit of 
generation numbers, so the "N commits" is actually likely _zero_ for 
most tags, because the tags have strictly lower generation number. In 
those cases, we can terminate without any walk at all.

Thanks! -Stolee

Jeff King· Oct 17, 2018, 18:31 UTC · re: Elijah Newren · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On Wed, Oct 17, 2018 at 11:00:03AM -0700, Elijah Newren wrote:
Show 15 quoted lines
> Digging in, almost all the time was CPU-bound and spent in
> add_missing_tags()[2].  If I'm reading the code correctly, it appears
> that function loops over each tag, calling in_merge_bases_many() once
> per tag.  Thus, for his case, we were potentially walking all of
> history of the main branch 2.5k times.  That seemed rather suboptimal.
> 
> Before attempting to optimize, I decided to try out the commit-graph
> with a version of git from pu.  While I expected a speed-up, I was a
> bit suprised that it was a factor of over 100; dropping the time for
> local dry-run push[2] to sub-second.  A quick look suggests that
> commit-graph doesn't fix the fact that we call in_merge_bases_many() N
> times from add_missing_tags() and thus likely need to do N merge base
> computations, it just makes each of the N much faster.  So, perhaps
> there's still another scaling issue we'll eventually need to address,
> but for now, I'm pretty excited about commit-graph.

Yeah, I think this case would probably still benefit from an all-points traversal. This want to be basically the same as what "git tag --merged" is doing, I would think (see ref-filter.c:do_merge_filter).

  As an aside, it looks like do_merge_filter uses prepare_revision_walk(),
  which IIRC means that it is susceptible to wrong answers due to
  clock skew (basically because of the use of commit timestamps for
  traversal order). This seems like another place where generation
  numbers could make a quiet improvement.
-Peff
Derrick Stolee· Oct 30, 2018, 14:22 UTC · re: Elijah Newren · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On 10/17/2018 2:00 PM, Elijah Newren wrote:
Show 18 quoted lines
> Hi,
>
> Just wanted to give a shout-out for the commit-graph work and how
> impressive it is.  I had an internal report from a user that git
> pushes containing only one new tiny commit were taking over a minute
> (in a moderate size repo with good network connectivity). After
> digging for a while, I noticed three unusual things about the repo[1]:
>    * he had push.followTags set to true
>    * upstream repo had about 20k tags (despite only 55k commits)
>    * his repo had an additional 2.5k tags, but none of these were in
>      the history of the branches he was pushing and thus would not be
>      included in any pushes.
>
> Digging in, almost all the time was CPU-bound and spent in
> add_missing_tags()[2].  If I'm reading the code correctly, it appears
> that function loops over each tag, calling in_merge_bases_many() once
> per tag.  Thus, for his case, we were potentially walking all of
> history of the main branch 2.5k times.  That seemed rather suboptimal.
Elijah,

Do you still have this repo around? Could you by chance test the performance with the new algorithm for add_missing_tags() in [1]? Specifically, please test it without a commit-graph file, since your data shape already makes use of generation numbers pretty well.

Thanks, -Stolee

[1] https://public-inbox.org/git/pull.60.git.gitgitgadget@gmail.com/T/#t
Elijah Newren· Oct 31, 2018, 05:45 UTC · re: Derrick Stolee · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On Tue, Oct 30, 2018 at 7:22 AM Derrick Stolee <stolee@gmail.com> wrote:
Show 30 quoted lines
>
> On 10/17/2018 2:00 PM, Elijah Newren wrote:
> > Hi,
> >
> > Just wanted to give a shout-out for the commit-graph work and how
> > impressive it is.  I had an internal report from a user that git
> > pushes containing only one new tiny commit were taking over a minute
> > (in a moderate size repo with good network connectivity). After
> > digging for a while, I noticed three unusual things about the repo[1]:
> >    * he had push.followTags set to true
> >    * upstream repo had about 20k tags (despite only 55k commits)
> >    * his repo had an additional 2.5k tags, but none of these were in
> >      the history of the branches he was pushing and thus would not be
> >      included in any pushes.
> >
> > Digging in, almost all the time was CPU-bound and spent in
> > add_missing_tags()[2].  If I'm reading the code correctly, it appears
> > that function loops over each tag, calling in_merge_bases_many() once
> > per tag.  Thus, for his case, we were potentially walking all of
> > history of the main branch 2.5k times.  That seemed rather suboptimal.
>
> Elijah,
>
> Do you still have this repo around? Could you by chance test the
> performance with the new algorithm for add_missing_tags() in [1]?
> Specifically, please test it without a commit-graph file, since your
> data shape already makes use of generation numbers pretty well.
>
> Thanks,
> -Stolee

I nuked it, but turns out I had a backup that I found after digging around for a bit. I'll post a comment on the series with the results.

By the way, I've been running pu for about a week with this tweak:
diff --git a/revision.c b/revision.c
index b5108b75ab..d20c687e71 100644
--- a/revision.c
+++ b/revision.c
@@ -1457,6 +1457,7 @@ void repo_init_revisions(struct repository *r,
        revs->pruning.change = file_change;
        revs->pruning.change_fn_data = revs;
        revs->sort_order = REV_SORT_IN_GRAPH_ORDER;
+       revs->topo_order = 1;
        revs->dense = 1;
        revs->prefix = prefix;
        revs->max_age = -1;

Only ran into one small problem once, and it wasn't commit-graph
related; rather it was related to my above patch and needing to not
have topo_order be set.  (I just bailed and used my older
system-installed git from /usr/bin/ in that one case.)  So, I think
the commit-graph stuff is looking pretty good, and I find the recent
thread on further improvements with corrected commit date (among other
possibilities) very intriguing...even if I haven't had much time to
comment or test recently.
Ævar Arnfjörð Bjarmason· Oct 30, 2018, 16:22 UTC · re: Elijah Newren · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On Wed, Oct 17, 2018 at 8:41 PM Elijah Newren <newren@gmail.com> wrote:
> (And in the mean time I gave the user a one-liner to nuke his
> local-only tags that I suspect he doesn't need.)

Just a note that you can usually set 'fetch.pruneTags=true' these days to make that happen.

Elijah Newren· Oct 31, 2018, 05:46 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: commit-graph is cool (overcoming add_missing_tags() perf issues)

On Tue, Oct 30, 2018 at 9:23 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 7 quoted lines
>
> On Wed, Oct 17, 2018 at 8:41 PM Elijah Newren <newren@gmail.com> wrote:
> > (And in the mean time I gave the user a one-liner to nuke his
> > local-only tags that I suspect he doesn't need.)
>
> Just a note that you can usually set 'fetch.pruneTags=true' these days
> to make that happen.
TIL.  Thanks for the heads up.

← back to recent threads