summaryrefslogtreecommitdiff
path: root/ls-refs.c
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2021-09-01 12:54:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-01 17:20:39 (GMT)
commit70afef5cdf29b5159f18df1b93722055f78740f8 (patch)
tree596bb4193b09a26e91d2450a77cbf00e87a59497 /ls-refs.c
parent96328398b3803c96f6a91edc39ccebd4bb9dd12c (diff)
downloadgit-70afef5cdf29b5159f18df1b93722055f78740f8.zip
git-70afef5cdf29b5159f18df1b93722055f78740f8.tar.gz
git-70afef5cdf29b5159f18df1b93722055f78740f8.tar.bz2
upload-pack: use stdio in send_ref callbacks
In both protocol v0 and v2, upload-pack writes one pktline packet per advertised ref to stdout. That means one or two write(2) syscalls per ref. This is problematic if these writes become network sends with high overhead. This commit changes both send_ref callbacks to use buffered IO using stdio. To give an example of the impact: I set up a single-threaded loop that calls ls-remote (with HTTP and protocol v2) on a local GitLab instance, on a repository with 11K refs. When I switch from Git v2.32.0 to this patch, I see a 40% reduction in CPU time for Git, and 65% for Gitaly (GitLab's Git RPC service). So using buffered IO not only saves syscalls in upload-pack, it also saves time in things that consume upload-pack's output. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Jacob Vosmaer <jacob@gitlab.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ls-refs.c')
-rw-r--r--ls-refs.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ls-refs.c b/ls-refs.c
index 88f6c3f..e6a2dbd 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -105,7 +105,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
}
strbuf_addch(&refline, '\n');
- packet_write(1, refline.buf, refline.len);
+ packet_fwrite(stdout, refline.buf, refline.len);
strbuf_release(&refline);
return 0;
@@ -171,7 +171,7 @@ int ls_refs(struct repository *r, struct strvec *keys,
strvec_push(&data.prefixes, "");
for_each_fullref_in_prefixes(get_git_namespace(), data.prefixes.v,
send_ref, &data, 0);
- packet_flush(1);
+ packet_fflush(stdout);
strvec_clear(&data.prefixes);
return 0;
}