* [PATCH 2/2] fetch: skip computing output width when not printing anything [not found] <cover.1643364639.git.ps@pks.im> @ 2022-01-28 10:17 ` Patrick Steinhardt 0 siblings, 0 replies; 2+ messages in thread From: Patrick Steinhardt @ 2022-01-28 10:17 UTC (permalink / raw) To: git [-- Attachment #1: Type: text/plain, Size: 2789 bytes --] When updating references via git-fetch(1), then by default we report to the user which references have been changed. This output is formatted in a nice table such that the different columns are aligned. Because the first column contains abbreviated object IDs we thus need to iterate over all refs which have changed and compute the minimum length for their respective abbreviated hashes. While this effort makes sense in most cases, it is wasteful when the user passes the `--quiet` flag: we don't print the summary, but still compute the length. Skip computing the summary width when the user asked for us to be quiet. This gives us a small speedup of nearly 10% when doing a dry-run mirror-fetch in a repository with thousands of references being updated: Benchmark 1: git fetch --prune --dry-run +refs/*:refs/* (HEAD~) Time (mean ± σ): 34.048 s ± 0.233 s [User: 30.739 s, System: 4.640 s] Range (min … max): 33.785 s … 34.296 s 5 runs Benchmark 2: git fetch --prune --dry-run +refs/*:refs/* (HEAD) Time (mean ± σ): 30.768 s ± 0.287 s [User: 27.534 s, System: 4.565 s] Range (min … max): 30.432 s … 31.181 s 5 runs Summary 'git fetch --prune --dry-run +refs/*:refs/* (HEAD)' ran 1.11 ± 0.01 times faster than 'git fetch --prune --dry-run +refs/*:refs/* (HEAD~)' Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/fetch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 5f06b21f8e..ebbde5d56d 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1093,12 +1093,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, struct ref *rm; char *url; int want_status; - int summary_width = transport_summary_width(ref_map); + int summary_width = 0; rc = open_fetch_head(&fetch_head); if (rc) return -1; + if (verbosity >= 0) + summary_width = transport_summary_width(ref_map); + if (raw_url) url = transport_anonymize_url(raw_url); else @@ -1344,7 +1347,6 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map, int url_len, i, result = 0; struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map); char *url; - int summary_width = transport_summary_width(stale_refs); const char *dangling_msg = dry_run ? _(" (%s will become dangling)") : _(" (%s has become dangling)"); @@ -1373,6 +1375,8 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map, } if (verbosity >= 0) { + int summary_width = transport_summary_width(stale_refs); + for (ref = stale_refs; ref; ref = ref->next) { struct strbuf sb = STRBUF_INIT; if (!shown_url) { -- 2.35.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 0/2] fetch: speed up mirror-fetches with many refs @ 2022-01-28 10:15 Patrick Steinhardt 2022-01-28 10:19 ` [PATCH 2/2] fetch: skip computing output width when not printing anything Patrick Steinhardt 0 siblings, 1 reply; 2+ messages in thread From: Patrick Steinhardt @ 2022-01-28 10:15 UTC (permalink / raw) To: git [-- Attachment #1: Type: text/plain, Size: 544 bytes --] Hi, this patch series aims to speed up mirror-fetches in repositories with huge amounts of refs. It contains two patches which together speed up git-fetch(1) in a repository with about 2,1 million references by roughly 30%. Patrick Patrick Steinhardt (2): fetch-pack: use commit-graph when computing cutoff fetch: skip computing output width when not printing anything builtin/fetch.c | 8 ++++++-- fetch-pack.c | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) -- 2.35.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] fetch: skip computing output width when not printing anything 2022-01-28 10:15 [PATCH 0/2] fetch: speed up mirror-fetches with many refs Patrick Steinhardt @ 2022-01-28 10:19 ` Patrick Steinhardt 0 siblings, 0 replies; 2+ messages in thread From: Patrick Steinhardt @ 2022-01-28 10:19 UTC (permalink / raw) To: git [-- Attachment #1: Type: text/plain, Size: 2836 bytes --] When updating references via git-fetch(1), then by default we report to the user which references have been changed. This output is formatted in a nice table such that the different columns are aligned. Because the first column contains abbreviated object IDs we thus need to iterate over all refs which have changed and compute the minimum length for their respective abbreviated hashes. While this effort makes sense in most cases, it is wasteful when the user passes the `--quiet` flag: we don't print the summary, but still compute the length. Skip computing the summary width when the user asked for us to be quiet. This gives us a small speedup of nearly 10% when doing a dry-run mirror-fetch in a repository with thousands of references being updated: Benchmark 1: git fetch --prune --dry-run +refs/*:refs/* (HEAD~) Time (mean ± σ): 34.048 s ± 0.233 s [User: 30.739 s, System: 4.640 s] Range (min … max): 33.785 s … 34.296 s 5 runs Benchmark 2: git fetch --prune --dry-run +refs/*:refs/* (HEAD) Time (mean ± σ): 30.768 s ± 0.287 s [User: 27.534 s, System: 4.565 s] Range (min … max): 30.432 s … 31.181 s 5 runs Summary 'git fetch --prune --dry-run +refs/*:refs/* (HEAD)' ran 1.11 ± 0.01 times faster than 'git fetch --prune --dry-run +refs/*:refs/* (HEAD~)' Signed-off-by: Patrick Steinhardt <ps@pks.im> --- [Resend with correct In-Reply-To header.] builtin/fetch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 5f06b21f8e..ebbde5d56d 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1093,12 +1093,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, struct ref *rm; char *url; int want_status; - int summary_width = transport_summary_width(ref_map); + int summary_width = 0; rc = open_fetch_head(&fetch_head); if (rc) return -1; + if (verbosity >= 0) + summary_width = transport_summary_width(ref_map); + if (raw_url) url = transport_anonymize_url(raw_url); else @@ -1344,7 +1347,6 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map, int url_len, i, result = 0; struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map); char *url; - int summary_width = transport_summary_width(stale_refs); const char *dangling_msg = dry_run ? _(" (%s will become dangling)") : _(" (%s has become dangling)"); @@ -1373,6 +1375,8 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map, } if (verbosity >= 0) { + int summary_width = transport_summary_width(stale_refs); + for (ref = stale_refs; ref; ref = ref->next) { struct strbuf sb = STRBUF_INIT; if (!shown_url) { -- 2.35.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-28 10:19 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <cover.1643364639.git.ps@pks.im> 2022-01-28 10:17 ` [PATCH 2/2] fetch: skip computing output width when not printing anything Patrick Steinhardt 2022-01-28 10:15 [PATCH 0/2] fetch: speed up mirror-fetches with many refs Patrick Steinhardt 2022-01-28 10:19 ` [PATCH 2/2] fetch: skip computing output width when not printing anything Patrick Steinhardt
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 NNTP newsgroup(s).