Git development
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Subject: Re: [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"
Date: Wed, 18 Nov 2026 16:52:45 +0100	[thread overview]
Message-ID: <87h5hejfw2.fsf@dev.null.iotcl.com.invalid> (raw)
In-Reply-To: <20261118-pks-reflog-expire-performance-v1-3-10b9263566a8@pks.im>

Patrick Steinhardt <ps@pks.im> writes:

> The "reflog-expire" maintenance task is responsible for expiring reflog
> entries that are older than either "gc.reflogExpire" for entries that
> are still reachable, or "gc.reflogExpireUnreachable" for those that are
> not reachable.
>
> When executed with "--auto", the condition that we use to trigger this
> task verifies whether the number of reflog entries that we would prune
> is larger than "maintenance.reflog-expire.auto". This is evaluated by
> walking the "HEAD" reflog, where we then check every entry by calling
> `should_expire_reflog_ent()`. That function will then check whether the
> reflog entry refers to a commit that is reachable or not, and depending
> on the outcome compares against either "gc.reflogExpire", or against
> both "gc.reflogExpire" and "gc.reflogExpireUnreachable".
>
> To decide reachability the caller has to call `reflog_expiry_prepare()`,
> which amongst other things also performs a reachability walk for a given
> refname. But we don't do that in the "reflog-expire" maintenance task,
> and hence every single reflog entry will be considered unreachable and
> thus we'd consider many reachable entries prunable even though they
> won't be pruned. So we overcount the number of prunable entries quite a
> bit and will thus trigger `git reflog expire` even though it won't do
> anything.
>
> Now we could easiliy fix that by calling `reflog_expiry_prepare()`.

Do you mean "not calling"?

Anyhow, from reading the diff and the surrounding code, it's not clear
to me where this is/was called?

The fix itself though makes sense. You basically pull out the first
condition from should_expire_reflog_ent() and skip the reachability
check. 

> But in the case of auto-maintenance it has the big downside that we now have
> to perform a reachability walk in the foreground, and that may be quite
> expensive. The whole point of those auto-conditions is to use heuristics
> that are fast to evaluate though so that the time we have to block is
> reduced as much as possible.
>
> Instead, adapt the heuristic to only evaluate reflog entries against
> "gc.reflogExpire". This of course means that we're now undercounting the
> number of prunable entries. But as part of background maintenance that
> feels like a reasonable tradeoff, and a user that really wants to prune
> unreachable reflog entries can either execute git-maintenance(1) without
> "--auto", or they can run `git reflog expire` directly.

Yeah, makes sense to me to undercount.

> In any case, the consequence is that we only spawn git-reflog(1) now in
> those cases where it would indeed prune entries. And in my own working
> copy of "git.git" that I use daily that results in quite a performance
> improvement:
>
>   Benchmark 1: git maintenance run --auto (commit = HEAD~) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    385.2 ms  ±     1.9 ms     382.7 ms  …   388.6 ms
>     Memory       116.8 MiB ±     0.1 MiB    116.7 MiB …   117.0 MiB
>
>   Benchmark 2: git maintenance run --auto (commit = HEAD) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time     17.9 ms  ±     0.7 ms      17.2 ms  …    19.6 ms           -95.4%  (21.5x faster)
>     Memory        81.0 MiB ±     0.1 MiB     80.7 MiB …    81.2 MiB          -30.7%  (1.4x less)
>
> Note that this improvement can be observed after every single command
> that triggers auto-maintenance, so this is overall quite an important
> optimization.

Seems to me the tradeoff is worthwhile.

-- 
Laters,
Toon

  reply	other threads:[~2026-11-18 15:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  9:30 [PATCH 0/4] Improve performance of reflog expiration Patrick Steinhardt
2026-11-18  9:31 ` [PATCH 1/4] refs/reftable: don't write new table on dry-run expire Patrick Steinhardt
2026-11-18 11:28   ` Karthik Nayak
2026-11-18 12:05     ` Patrick Steinhardt
2026-11-18 16:51   ` Junio C Hamano
2026-11-18  9:31 ` [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op Patrick Steinhardt
2026-11-18 11:33   ` Karthik Nayak
2026-11-18 12:05     ` Patrick Steinhardt
2026-11-18 15:34   ` Toon Claes
2026-11-18  9:31 ` [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto" Patrick Steinhardt
2026-11-18 15:52   ` Toon Claes [this message]
2026-11-18  9:31 ` [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto" Patrick Steinhardt
2026-11-18 15:54   ` Toon Claes
2026-11-18 15:56 ` [PATCH 0/4] Improve performance of reflog expiration Toon Claes

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=87h5hejfw2.fsf@dev.null.iotcl.com.invalid \
    --to=toon@iotcl.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox