git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Orgad Shaneh <orgads@gmail.com>, Orgad Shaneh <orgads@gmail.com>
Subject: [PATCH v2] fetch: do not look for submodule changes in unchanged refs
Date: Fri, 04 Sep 2020 13:50:49 +0000	[thread overview]
Message-ID: <pull.720.v2.git.1599227449987.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.720.git.1599056635276.gitgitgadget@gmail.com>

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(-)

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

      parent reply	other threads:[~2020-09-04 13:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 14:23 [PATCH] fetch: do not look for submodule changes in unchanged refs Orgad Shaneh via GitGitGadget
2020-09-02 20:26 ` Junio C Hamano
2020-09-07 15:49   ` Orgad Shaneh
2020-09-04 13:50 ` Orgad Shaneh via GitGitGadget [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.720.v2.git.1599227449987.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=orgads@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).