From: Adrian Ratiu <adrian.ratiu@collabora•com>
To: git@vger•kernel.org
Cc: Junio C Hamano <gitster@pobox•com>,
Patrick Steinhardt <ps@pks•im>,
Emily Shaffer <emilyshaffer@google•com>,
Jeff King <peff@peff•net>,
Adrian Ratiu <adrian.ratiu@collabora•com>
Subject: [PATCH 1/1] builtin/receive-pack: avoid spinning no-op sideband async threads
Date: Mon, 2 Mar 2026 21:17:04 +0200 [thread overview]
Message-ID: <20260302191704.1814567-2-adrian.ratiu@collabora.com> (raw)
In-Reply-To: <20260302191704.1814567-1-adrian.ratiu@collabora.com>
Exit early if the hooks do not exist, to avoid spinning up/down
sideband async threads which no-op.
It is important to call the hook_exists() API provided by hook.[ch]
because it covers both config-defined hooks and the "traditional"
hooks from the hookdir. find_hook() only covers the hookdir hooks.
The regression happened because the no-op async threads add some
additional overhead which can be measured with the receive-refs test
of the benchmarks suite [1].
Reproduced using:
cd benchmarks/receive-refs && \
./run --revisions /path/to/git \
fc148b146ad41be71a7852c4867f0773cbfe1ff9~,fc148b146ad41be71a7852c4867f0773cbfe1ff9 \
--parameter-list refformat reftable --parameter-list refcount 10000
1: https://gitlab.com/gitlab-org/data-access/git/benchmarks
Fixes: fc148b146ad4 ("receive-pack: convert update hooks to new API")
Reported-by: Patrick Steinhardt <ps@pks•im>
Helped-by: Jeff King <peff@peff•net>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora•com>
---
builtin/receive-pack.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 139a227e71..6376c191c7 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -934,6 +934,9 @@ static int run_receive_hook(struct command *commands,
int saved_stderr = -1;
int ret;
+ if (!hook_exists(the_repository, hook_name))
+ return 0;
+
/* if there are no valid commands, don't invoke the hook at all. */
while (iter && skip_broken && (iter->error_string || iter->did_not_exist))
iter = iter->next;
@@ -980,6 +983,9 @@ static int run_update_hook(struct command *cmd)
int saved_stderr = -1;
int code;
+ if (!hook_exists(the_repository, "update"))
+ return 0;
+
strvec_pushl(&opt.args,
cmd->ref_name,
oid_to_hex(&cmd->old_oid),
@@ -1674,6 +1680,9 @@ static void run_update_post_hook(struct command *commands)
int sideband_async_started = 0;
int saved_stderr = -1;
+ if (!hook_exists(the_repository, "post-update"))
+ return;
+
for (cmd = commands; cmd; cmd = cmd->next) {
if (cmd->error_string || cmd->did_not_exist)
continue;
--
2.52.0.732.gb351b5166d.dirty
next prev parent reply other threads:[~2026-03-02 19:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 19:17 [PATCH 0/1] Fix update hook perf regression in next Adrian Ratiu
2026-03-02 19:17 ` Adrian Ratiu [this message]
2026-03-02 21:40 ` [PATCH 1/1] builtin/receive-pack: avoid spinning no-op sideband async threads Junio C Hamano
2026-03-03 12:47 ` Adrian Ratiu
2026-03-03 6:11 ` Patrick Steinhardt
2026-03-03 12:45 ` Adrian Ratiu
2026-03-03 13:28 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260302191704.1814567-2-adrian.ratiu@collabora.com \
--to=adrian.ratiu@collabora$(echo .)com \
--cc=emilyshaffer@google$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=peff@peff$(echo .)net \
--cc=ps@pks$(echo .)im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox