threads / patch / 54178

patchfetch: do not look for submodule changes in unchanged refs

Subject: [PATCH] fetch: do not look for submodule changes in unchanged refs

## tl;dr

4 messages between Sep 2, 2020 and Sep 7, 2020. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Orgad Shaneh via GitGitGadget· Sep 2, 2020, 14:23 UTC · lore
From: Orgad Shaneh <orgads@gmail.com>

This operation is very expensive, as it scans all the refs using setup_revisions, which resolves each ref, including checking if it is ambiguous, or if it is a file name etc.

There is no reason to do all that for refs that haven't changed in this fetch.

Reported here: https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-iAjxRCpqNK5bnhRg@mail.gmail.com/

Amends commit be76c2128234d94b47f7087152ee55d08bb65d88.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
    fetch: do not look for submodule changes in unchanged refs
    
    This operation is very expensive, as it scans all the refs using
    setup_revisions, which resolves each ref, including checking if it is
    ambiguous, or if it is a file name etc.
    
    There is no reason to do all that for refs that hasn't changed in this
    fetch.
    
    Reported here:
    https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-iAjxRCpqNK5bnhRg@mail.gmail.com/
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-720%2Forgads%2Ffetch-less-submodules-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-720/orgads/fetch-less-submodules-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/720
 builtin/fetch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Show changes to builtin/fetch.c +3 −1
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 0f23dd4b8c..d3f922fc89 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -958,8 +958,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				ref->force = rm->peer_ref->force;
 			}
 
-			if (recurse_submodules != RECURSE_SUBMODULES_OFF)
+			if (recurse_submodules != RECURSE_SUBMODULES_OFF &&
+			    (!rm->peer_ref || !oideq(&ref->old_oid, &ref->new_oid))) {
 				check_for_new_submodule_commits(&rm->old_oid);
+			}
 
 			if (!strcmp(rm->name, "HEAD")) {
 				kind = "";

base-commit: e19713638985533ce461db072b49112da5bd2042
-- 
gitgitgadget
Junio C Hamano· Sep 2, 2020, 20:26 UTC · re: Orgad Shaneh via GitGitGadget · lore

Re: [PATCH] fetch: do not look for submodule changes in unchanged refs

"Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> From: Orgad Shaneh <orgads@gmail.com>
>
> This operation is very expensive, as it scans all the refs using
> setup_revisions, which resolves each ref, including checking if it
> is ambiguous, or if it is a file name etc.

Nobody can tell what "This operation" is without looking at the patch/diff text. Our commit message typically gives minimum explanation of the situation and the problem it tries to solve first to make it self sufficient. And then we go on to order the code base to be in a better shape. Something along the lines of ...

    When fetching recursively with submodules, for each ref in the
    superproject, we call check_for_new_submodule_commits() to
    figure out X and Y for the object the ref was pointing at before
    the fetch in the superproject, in order to ensure Z.  This is
    expensive because of A, B and C, but it unnecessary if the fetch
    in the superproject did not update the ref (i.e. the objects
    that are required to exist in the submodule did not change).
    Check if we are making any change to the ref, and skip the check
    if we aren't.

... but I didn't fill the most important bits in the above, as by now you, as the person who encountered the issue and figured out a good way to solve it, would know what to fill the placeholders with far better than I would ;-)

Show 7 quoted lines
> There is no reason to do all that for refs that haven't changed in this
> fetch.
>
> Reported here:
> https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-iAjxRCpqNK5bnhRg@mail.gmail.com/
>
> Amends commit be76c2128234d94b47f7087152ee55d08bb65d88.

I am not sure what this reference is trying to achieve. Fixing a bug in be76c212 (fetch: ensure submodule objects fetched, 2018-12-06)? If so, please say so more directly, perhaps like

    be76c212 (fetch: ensure submodule objects fetched, 2018-12-06)
    tried to do what we are trying to do here, but it botched the
    exectuion by forgetting the fact that ...
or somesuch.  The cited commit says
   The submodule checks were done only when a ref in the
   superproject changed,...

so it is not clear what we are really fixing with this patch, though. Is the assertion "checks were done only when changed" it made incorrect and instead we were doing unnecessary check always?

Show 13 quoted lines
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 0f23dd4b8c..d3f922fc89 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -958,8 +958,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
>  				ref->force = rm->peer_ref->force;
>  			}
>  
> -			if (recurse_submodules != RECURSE_SUBMODULES_OFF)
> +			if (recurse_submodules != RECURSE_SUBMODULES_OFF &&
> +			    (!rm->peer_ref || !oideq(&ref->old_oid, &ref->new_oid))) {
>  				check_for_new_submodule_commits(&rm->old_oid);
> +			}

The original before be76c212 fed ref->new_oid to the check function. Now that we are using ref->{old,new}_oid in the condition, would it make more sense to pass ref->new_oid like we did before the commit, or is that an object that is different from rm->old_oid?

Thanks.
>  			if (!strcmp(rm->name, "HEAD")) {
>  				kind = "";
>
> base-commit: e19713638985533ce461db072b49112da5bd2042
Orgad Shaneh· Sep 7, 2020, 15:49 UTC · re: Junio C Hamano · lore

Re: [PATCH] fetch: do not look for submodule changes in unchanged refs

Hi Junio,
Thanks for the detailed review. I posted a new commit message.
On Wed, Sep 2, 2020 at 11:26 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 30 quoted lines
>
> "Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Orgad Shaneh <orgads@gmail.com>
> >
> > This operation is very expensive, as it scans all the refs using
> > setup_revisions, which resolves each ref, including checking if it
> > is ambiguous, or if it is a file name etc.
>
> Nobody can tell what "This operation" is without looking at the
> patch/diff text.  Our commit message typically gives minimum
> explanation of the situation and the problem it tries to solve first
> to make it self sufficient.  And then we go on to order the code
> base to be in a better shape.  Something along the lines of ...
>
>     When fetching recursively with submodules, for each ref in the
>     superproject, we call check_for_new_submodule_commits() to
>     figure out X and Y for the object the ref was pointing at before
>     the fetch in the superproject, in order to ensure Z.  This is
>     expensive because of A, B and C, but it unnecessary if the fetch
>     in the superproject did not update the ref (i.e. the objects
>     that are required to exist in the submodule did not change).
>
>     Check if we are making any change to the ref, and skip the check
>     if we aren't.
>
> ... but I didn't fill the most important bits in the above, as by
> now you, as the person who encountered the issue and figured out a
> good way to solve it, would know what to fill the placeholders with
> far better than I would ;-)
That was very helpful. Thanks.
Show 20 quoted lines
> [... snip ...]
> > diff --git a/builtin/fetch.c b/builtin/fetch.c
> > index 0f23dd4b8c..d3f922fc89 100644
> > --- a/builtin/fetch.c
> > +++ b/builtin/fetch.c
> > @@ -958,8 +958,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
> >                               ref->force = rm->peer_ref->force;
> >                       }
> >
> > -                     if (recurse_submodules != RECURSE_SUBMODULES_OFF)
> > +                     if (recurse_submodules != RECURSE_SUBMODULES_OFF &&
> > +                         (!rm->peer_ref || !oideq(&ref->old_oid, &ref->new_oid))) {
> >                               check_for_new_submodule_commits(&rm->old_oid);
> > +                     }
>
> The original before be76c212 fed ref->new_oid to the check
> function.  Now that we are using ref->{old,new}_oid in the
> condition, would it make more sense to pass ref->new_oid
> like we did before the commit, or is that an object that is
> different from rm->old_oid?

I think that was the whole point of this commit, to cover the case of !rm->peer_ref, for newly fetched refs. On this case, ref is NULL.

Show 6 quoted lines
> Thanks.
>
> >                       if (!strcmp(rm->name, "HEAD")) {
> >                               kind = "";
> >
> > base-commit: e19713638985533ce461db072b49112da5bd2042
- Orgad
Orgad Shaneh via GitGitGadget· Sep 4, 2020, 13:50 UTC · re: Orgad Shaneh via GitGitGadget · lore

[PATCH v2] fetch: do not look for submodule changes in unchanged refs

From: Orgad Shaneh <orgads@gmail.com>

When fetching recursively with submodules, for each ref in the superproject, we call check_for_new_submodule_commits() which collects all the objects that have to be checked for submodule changes on calculate_changed_submodule_paths(). On the first call, it also collects all the existing refs for excluding them from the scan.

calculate_changed_submodule_paths() creates an argument array with all the collected new objects, followed by --not and all the old objects. This argv is passed to setup_revisions, which parses each argument, converts it back to an oid and resolves the object. The parsing itself also does redundant work, because it is treated like user input, while in fact it is a full oid. So it needlessly attempts to look it up as ref (checks if it has ^, ~ etc.), checks if it is a file name etc.

For a repository with many refs, all of this is expensive. But if the fetch in the superproject did not update the ref (i.e. the objects that are required to exist in the submodule did not change), there is no need to include it in the list.

Before commit be76c212 (fetch: ensure submodule objects fetched, 2018-12-06), submodule reference changes were only detected for refs that were changed, but not for new refs. This commit covered also this case, but what it did was to just include every ref.

This change should reduce the number of scanned refs by about half (except the case of a no-op fetch, which will not scan any ref), because all the existing refs will still be listed after --not.

The regression was reported here: https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM- iAjxRCpqNK5bnhRg@mail.gmail.com/

Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
    fetch: do not look for submodule changes in unchanged refs
    
    This operation is very expensive, as it scans all the refs using
    setup_revisions, which resolves each ref, including checking if it is
    ambiguous, or if it is a file name etc.
    
    There is no reason to do all that for refs that hasn't changed in this
    fetch.
    
    Reported here:
    https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-iAjxRCpqNK5bnhRg@mail.gmail.com/
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-720%2Forgads%2Ffetch-less-submodules-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-720/orgads/fetch-less-submodules-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/720
Range-diff vs v1:
 1:  0f978f487d ! 1:  5348cd7ec8 fetch: do not look for submodule changes in unchanged refs
     @@ Metadata
       ## Commit message ##
          fetch: do not look for submodule changes in unchanged refs
      
     -    This operation is very expensive, as it scans all the refs using
     -    setup_revisions, which resolves each ref, including checking if it
     -    is ambiguous, or if it is a file name etc.
     +    When fetching recursively with submodules, for each ref in the
     +    superproject, we call check_for_new_submodule_commits() which collects all
     +    the objects that have to be checked for submodule changes on
     +    calculate_changed_submodule_paths(). On the first call, it also collects all
     +    the existing refs for excluding them from the scan.
      
     -    There is no reason to do all that for refs that haven't changed in this
     -    fetch.
     +    calculate_changed_submodule_paths() creates an argument array with all the
     +    collected new objects, followed by --not and all the old objects. This argv
     +    is passed to setup_revisions, which parses each argument, converts it back
     +    to an oid and resolves the object. The parsing itself also does redundant
     +    work, because it is treated like user input, while in fact it is a full
     +    oid. So it needlessly attempts to look it up as ref (checks if it has ^, ~
     +    etc.), checks if it is a file name etc.
      
     -    Reported here:
     -    https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-iAjxRCpqNK5bnhRg@mail.gmail.com/
     +    For a repository with many refs, all of this is expensive. But if the fetch
     +    in the superproject did not update the ref (i.e. the objects that are
     +    required to exist in the submodule did not change), there is no need to
     +    include it in the list.
      
     -    Amends commit be76c2128234d94b47f7087152ee55d08bb65d88.
     +    Before commit be76c212 (fetch: ensure submodule objects fetched,
     +    2018-12-06), submodule reference changes were only detected for refs that
     +    were changed, but not for new refs. This commit covered also this case, but
     +    what it did was to just include every ref.
     +
     +    This change should reduce the number of scanned refs by about half (except
     +    the case of a no-op fetch, which will not scan any ref), because all the
     +    existing refs will still be listed after --not.
     +
     +    The regression was reported here:
     +    https://public-inbox.org/git/CAGHpTBKSUJzFSWc=uznSu2zB33qCSmKXM-
     +    iAjxRCpqNK5bnhRg@mail.gmail.com/
      
          Signed-off-by: Orgad Shaneh <orgads@gmail.com>
      
 builtin/fetch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Show changes to builtin/fetch.c +3 −1
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 0f23dd4b8c..d3f922fc89 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -958,8 +958,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				ref->force = rm->peer_ref->force;
 			}
 
-			if (recurse_submodules != RECURSE_SUBMODULES_OFF)
+			if (recurse_submodules != RECURSE_SUBMODULES_OFF &&
+			    (!rm->peer_ref || !oideq(&ref->old_oid, &ref->new_oid))) {
 				check_for_new_submodule_commits(&rm->old_oid);
+			}
 
 			if (!strcmp(rm->name, "HEAD")) {
 				kind = "";

base-commit: e19713638985533ce461db072b49112da5bd2042
-- 
gitgitgadget

← back to recent threads