threads / patch / 66869

patch, 4 partsImprove performance of reflog expiration

Subject: [PATCH 0/4] Improve performance of reflog expiration

## tl;dr

The auto-condition for reflog expiry treated every entry as unreachable, so git maintenance kept doing work in the foreground that it did not need to do. Read the story.

replies: 17people: 4as markdown or json

Patrick Steinhardt· Nov 18, 2026, 09:30 UTC · lore
Hi,

I recently noticed that a bunch of commands started hanging for almost a second after they're essentially done already. As it turns out, this was caused by auto-maintenance, which was blocking in the foreground for ~800ms.

The root cause of this is that the auto-condition of "reflog-expire" doesn't properly evaluate reachability of reflog entries, so it instead considered every single reflog entry to point to an unreachable commit. Hence, all entries were evaluated against "gc.reflogExpireUnreachable" instead of "gc.reflogExpire", and thus the auto-condition significantly overcounts the number of entries that we'd prune. So every single run of git-maintenance(1) ultimately ended up spawning `git reflog expire`.

This is fixed by the last patch in this series. But I was a bit surprised that a no-op `git reflog expire` took this long, so the first two patches optimize the reftable backend to be more efficient, too. In my copy of "git.git":

  Benchmark 1: git maintenance run --auto (commit = master) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    853.2 ms  ±    99.9 ms     570.9 ms  …   901.9 ms
    Memory       117.5 MiB ±     0.3 MiB    117.2 MiB …   118.2 MiB
  Benchmark 2: git maintenance run --auto (commit = reftable-optimizations) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    392.3 ms  ±     2.3 ms     388.0 ms  …   396.6 ms           -54.0%  (2.2x faster)
    Memory       117.2 MiB ±     0.2 MiB    116.8 MiB …   117.4 MiB           -0.2%
  Benchmark 3: git maintenance run --auto (commit = auto-condition-optimizations) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time     18.6 ms  ±     1.1 ms      17.4 ms  …    20.9 ms           -97.8%  (45.8x faster)
    Memory        81.2 MiB ±     0.1 MiB     80.9 MiB …    81.4 MiB          -30.9%  (1.4x less)
So yeah, it's a bit more efficient now. :)
Thanks!
Patrick
---
Patrick Steinhardt (4):
      refs/reftable: don't write new table on dry-run expire
      refs/reftable: don't write new table when expire is a no-op
      builtin/maintenance: only consider `gc.reflogExpire` for "--auto"
      Documentation/config: fix typo in "maintenance.reflog-expire.auto"
 Documentation/config/maintenance.adoc |  2 +-
 builtin/gc.c                          | 33 +++++++++++++++++++++------------
 refs/reftable-backend.c               | 21 +++++++++++++++++----
 t/t0610-reftable-basics.sh            | 30 ++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 17 deletions(-)

--- base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4 change-id: 20261118-pks-reflog-expire-performance-e051b93f901a

Patrick Steinhardt· Nov 18, 2026, 09:31 UTC · re: Patrick Steinhardt · lore

[PATCH 1/4] refs/reftable: don't write new table on dry-run expire

The `git reflog expire` subcommand supports a dry-run flag. When set, we print what would be pruned without actually pruning anything on disk.

But even though the expectation is that the on-disk state won't change, the reftable backend still ends up writing a new reftable to disk that contains the changes. This is of course rather pointless, as we would have already printed the entries that we're about to prune at that point in time.

Skip writing the data, which provides a small speedup:
  Benchmark 1: git reflog expire --all --dry-run (commit = HEAD~) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    414.2 ms  ±     2.2 ms     411.8 ms  …   418.0 ms
    Memory       116.9 MiB ±     0.1 MiB    116.6 MiB …   117.0 MiB
  Benchmark 2: git reflog expire --all --dry-run (commit = HEAD) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    369.1 ms  ±     3.2 ms     361.9 ms  …   371.9 ms           -10.9%
    Memory       116.8 MiB ±     0.1 MiB    116.7 MiB …   117.0 MiB           -0.1%
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/reftable-backend.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Show changes to refs/reftable-backend.c +6 −2
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 3ba6a9ac0db..4216a18684d 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -2706,6 +2706,11 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
 		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
 
+	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
+		ret = 0;
+		goto done;
+	}
+
 	arg.refs = refs;
 	arg.records = rewritten;
 	arg.len = logs_nr;
@@ -2720,8 +2725,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 	 * Future improvement: we could skip writing records that were
 	 * not changed.
 	 */
-	if (!(flags & EXPIRE_REFLOGS_DRY_RUN))
-		ret = reftable_addition_commit(add);
+	ret = reftable_addition_commit(add);
 
 done:
 	if (add)
-- 
2.56.1.831.g720f3f5937.dirty
Karthik Nayak· Nov 18, 2026, 11:28 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire

Patrick Steinhardt <ps@pks.im> writes:
Show 21 quoted lines
> The `git reflog expire` subcommand supports a dry-run flag. When set, we
> print what would be pruned without actually pruning anything on disk.
>
> But even though the expectation is that the on-disk state won't change,
> the reftable backend still ends up writing a new reftable to disk that
> contains the changes. This is of course rather pointless, as we would
> have already printed the entries that we're about to prune at that point
> in time.
>
> Skip writing the data, which provides a small speedup:
>
>   Benchmark 1: git reflog expire --all --dry-run (commit = HEAD~) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    414.2 ms  ±     2.2 ms     411.8 ms  …   418.0 ms
>     Memory       116.9 MiB ±     0.1 MiB    116.6 MiB …   117.0 MiB
>
>   Benchmark 2: git reflog expire --all --dry-run (commit = HEAD) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    369.1 ms  ±     3.2 ms     361.9 ms  …   371.9 ms           -10.9%
>     Memory       116.8 MiB ±     0.1 MiB    116.7 MiB …   117.0 MiB           -0.1%
>
Nice find. Obviously the previous flow was wrong.
Show 25 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  refs/reftable-backend.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 3ba6a9ac0db..4216a18684d 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -2706,6 +2706,11 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
>  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
>
> +	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> +		ret = 0;
> +		goto done;
> +	}
> +
>  	arg.refs = refs;
>  	arg.records = rewritten;
>  	arg.len = logs_nr;
> @@ -2720,8 +2725,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	 * Future improvement: we could skip writing records that were
>  	 * not changed.
>  	 */
This comment doesn't seem to get removed in the following patch.
> -	if (!(flags & EXPIRE_REFLOGS_DRY_RUN))
> -		ret = reftable_addition_commit(add);
> +	ret = reftable_addition_commit(add);
>
The changes in this patch look sensible.
Show 5 quoted lines
>  done:
>  	if (add)
>
> --
> 2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 18, 2026, 12:05 UTC · re: Karthik Nayak · lore

Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire

On Wed, Nov 18, 2026 at 03:28:25AM -0800, Karthik Nayak wrote:
Show 23 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> > index 3ba6a9ac0db..4216a18684d 100644
> > --- a/refs/reftable-backend.c
> > +++ b/refs/reftable-backend.c
> > @@ -2706,6 +2706,11 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
> >  	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
> >  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
> >
> > +	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> > +		ret = 0;
> > +		goto done;
> > +	}
> > +
> >  	arg.refs = refs;
> >  	arg.records = rewritten;
> >  	arg.len = logs_nr;
> > @@ -2720,8 +2725,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
> >  	 * Future improvement: we could skip writing records that were
> >  	 * not changed.
> >  	 */
> 
> This comment doesn't seem to get removed in the following patch.

That's because I don't fully consider this comment to be addressed. If I understand correctly, this also speaks about the fact that we could drop rewriting entries in a finer-grained way. All I'm changing is that we now don't write any entries in case none of them need to be rewritten.

Patrick
Junio C Hamano· Nov 18, 2026, 16:51 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire

Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
> The `git reflog expire` subcommand supports a dry-run flag. When set, we
> print what would be pruned without actually pruning anything on disk.
>
> But even though the expectation is that the on-disk state won't change,
> the reftable backend still ends up writing a new reftable to disk that
> contains the changes. This is of course rather pointless, as we would
> have already printed the entries that we're about to prune at that point
> in time.

I hope I am right in assuming that the current code already has provisions to discard (or "not to use") this data written to the disk. If so, that means --dry-run is working correctly, and this change is a performance-only improvement. Is that the untold piece of information here?

Show 43 quoted lines
> Skip writing the data, which provides a small speedup:
>
>   Benchmark 1: git reflog expire --all --dry-run (commit = HEAD~) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    414.2 ms  ±     2.2 ms     411.8 ms  …   418.0 ms
>     Memory       116.9 MiB ±     0.1 MiB    116.6 MiB …   117.0 MiB
>
>   Benchmark 2: git reflog expire --all --dry-run (commit = HEAD) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    369.1 ms  ±     3.2 ms     361.9 ms  …   371.9 ms           -10.9%
>     Memory       116.8 MiB ±     0.1 MiB    116.7 MiB …   117.0 MiB           -0.1%
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  refs/reftable-backend.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 3ba6a9ac0db..4216a18684d 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -2706,6 +2706,11 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
>  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
>  
> +	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> +		ret = 0;
> +		goto done;
> +	}
> +
>  	arg.refs = refs;
>  	arg.records = rewritten;
>  	arg.len = logs_nr;
> @@ -2720,8 +2725,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	 * Future improvement: we could skip writing records that were
>  	 * not changed.
>  	 */
> -	if (!(flags & EXPIRE_REFLOGS_DRY_RUN))
> -		ret = reftable_addition_commit(add);
> +	ret = reftable_addition_commit(add);
>  
>  done:
>  	if (add)
Patrick Steinhardt· Nov 19, 2026, 11:59 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire

On Wed, Nov 18, 2026 at 08:51:41AM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > The `git reflog expire` subcommand supports a dry-run flag. When set, we
> > print what would be pruned without actually pruning anything on disk.
> >
> > But even though the expectation is that the on-disk state won't change,
> > the reftable backend still ends up writing a new reftable to disk that
> > contains the changes. This is of course rather pointless, as we would
> > have already printed the entries that we're about to prune at that point
> > in time.
> 
> I hope I am right in assuming that the current code already has
> provisions to discard (or "not to use") this data written to the
> disk.  If so, that means --dry-run is working correctly, and this
> change is a performance-only improvement.  Is that the untold piece
> of information here?

Yes. We write everything to disk, but instead of committing we then call `reftable_addition_destroy()`, which calls `reftable_addition_close()`, and that function in turn unlinks the table from disk again.

I'll adapt the commit message to make that explicit.
Patrick
Patrick Steinhardt· Nov 18, 2026, 09:31 UTC · re: Patrick Steinhardt · lore

[PATCH 2/4] refs/reftable: don't write new table when expire is a no-op

When executing `git reflog expire` we may of course end up not expiring any reflog entries because none of them are older than "gc.reflogExpire" or "gc.reflogExpireUnreachable". But even so, the reftable backend would end up writing a new table to disk anyway that contains basically an exact copy of the current reflog. And with the "--all" flag, that would happen once per existing reflog. This doesn't result in any correctness issues, but it is of course a lot of pointless busywork.

Skip writing and committing the new reftable in the case where there aren't any changes, which results in a nice speedup:

  Benchmark 1: git reflog expire --all (commit = HEAD~) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    736.0 ms  ±    11.7 ms     720.0 ms  …   752.3 ms
    Memory       117.2 MiB ±     0.1 MiB    117.1 MiB …   117.3 MiB
  Benchmark 2: git reflog expire --all (commit = HEAD) (10 runs)
                  mean     ±       σ          min     …     max
    Wall Time    370.3 ms  ±     3.7 ms     363.4 ms  …   375.6 ms           -49.7%  (2.0x faster)
    Memory       116.8 MiB ±     0.2 MiB    116.5 MiB …   117.1 MiB           -0.3%
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/reftable-backend.c    | 15 ++++++++++++---
 t/t0610-reftable-basics.sh | 30 ++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)
Show changes to 2 files +42 −3

refs/reftable-backend.c, t/t0610-reftable-basics.sh

diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 4216a18684d..e2027bb9c02 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -2607,6 +2607,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 	struct strbuf referent = STRBUF_INIT;
 	uint8_t *last_hash = NULL;
 	size_t logs_nr = 0, logs_alloc = 0, i;
+	bool has_changes = false;
 	unsigned int type = 0;
 	int ret;
 
@@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 				    logs[i].value.update.message,
 				    policy_cb_data)) {
 			dest->value_type = REFTABLE_LOG_DELETION;
+			has_changes = true;
 		} else {
-			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
+			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
+			    memcmp(dest->value.update.old_hash, last_hash,
+				   ref_store->repo->hash_algo->rawsz)) {
 				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
+				has_changes = true;
+			}
 			last_hash = logs[i].value.update.new_hash;
 		}
 	}
 
-	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
+	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid)) {
 		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
+		if (!oideq(&arg.update_oid, &oid))
+			has_changes = true;
+	}
 
-	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
+	if (!has_changes || (flags & EXPIRE_REFLOGS_DRY_RUN)) {
 		ret = 0;
 		goto done;
 	}
diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
index a7027458395..d808f1887f6 100755
--- a/t/t0610-reftable-basics.sh
+++ b/t/t0610-reftable-basics.sh
@@ -912,6 +912,36 @@ test_expect_success 'reflog: expiry empties reflog' '
 	)
 '
 
+test_expect_success 'reflog: expiry without changes does not write tables' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+
+		test_commit A &&
+		test_commit B &&
+		test_commit C &&
+		cp .git/reftable/tables.list expect &&
+
+		git reflog expire --all --expire=never --expire-unreachable=never &&
+		test_cmp expect .git/reftable/tables.list &&
+
+		git reflog expire --all --rewrite \
+			--expire=never --expire-unreachable=never &&
+		test_cmp expect .git/reftable/tables.list &&
+
+		git reflog expire --all --updateref \
+			--expire=never --expire-unreachable=never &&
+		test_cmp expect .git/reftable/tables.list &&
+
+		git reflog expire --all --dry-run --expire=all &&
+		test_cmp expect .git/reftable/tables.list &&
+
+		git reflog expire --all --expire=all &&
+		! test_cmp expect .git/reftable/tables.list
+	)
+'
+
 test_expect_success 'reflog: can be deleted' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&
-- 
2.56.1.831.g720f3f5937.dirty
Karthik Nayak· Nov 18, 2026, 11:33 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op

Patrick Steinhardt <ps@pks.im> writes:
Show 23 quoted lines
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 4216a18684d..e2027bb9c02 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -2607,6 +2607,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	struct strbuf referent = STRBUF_INIT;
>  	uint8_t *last_hash = NULL;
>  	size_t logs_nr = 0, logs_alloc = 0, i;
> +	bool has_changes = false;
>  	unsigned int type = 0;
>  	int ret;
>
> @@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  				    logs[i].value.update.message,
>  				    policy_cb_data)) {
>  			dest->value_type = REFTABLE_LOG_DELETION;
> +			has_changes = true;
>  		} else {
> -			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
> +			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
> +			    memcmp(dest->value.update.old_hash, last_hash,
> +				   ref_store->repo->hash_algo->rawsz)) {
>  				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
We can skip this second copy.
Show 10 quoted lines
> +				has_changes = true;
> +			}
>  			last_hash = logs[i].value.update.new_hash;
>  		}
>  	}
>
> -	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
> +	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid)) {
>  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
> +		if (!oideq(&arg.update_oid, &oid))
We now check if its changed, makes sense.
Show 8 quoted lines
> +			has_changes = true;
> +	}
>
> -	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> +	if (!has_changes || (flags & EXPIRE_REFLOGS_DRY_RUN)) {
>  		ret = 0;
>  		goto done;
>  	}
Nit: it would be nice to mention that we exit early to skip writing any
new tables.
Show 37 quoted lines
> diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
> index a7027458395..d808f1887f6 100755
> --- a/t/t0610-reftable-basics.sh
> +++ b/t/t0610-reftable-basics.sh
> @@ -912,6 +912,36 @@ test_expect_success 'reflog: expiry empties reflog' '
>  	)
>  '
>
> +test_expect_success 'reflog: expiry without changes does not write tables' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +
> +		test_commit A &&
> +		test_commit B &&
> +		test_commit C &&
> +		cp .git/reftable/tables.list expect &&
> +
> +		git reflog expire --all --expire=never --expire-unreachable=never &&
> +		test_cmp expect .git/reftable/tables.list &&
> +
> +		git reflog expire --all --rewrite \
> +			--expire=never --expire-unreachable=never &&
> +		test_cmp expect .git/reftable/tables.list &&
> +
> +		git reflog expire --all --updateref \
> +			--expire=never --expire-unreachable=never &&
> +		test_cmp expect .git/reftable/tables.list &&
> +
> +		git reflog expire --all --dry-run --expire=all &&
> +		test_cmp expect .git/reftable/tables.list &&
> +
> +		git reflog expire --all --expire=all &&
> +		! test_cmp expect .git/reftable/tables.list
> +	)
> +'
Nice. Could we add a similar test for the previous patch too?
Patrick Steinhardt· Nov 18, 2026, 12:05 UTC · re: Karthik Nayak · lore

Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op

On Wed, Nov 18, 2026 at 03:33:04AM -0800, Karthik Nayak wrote:
Show 43 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> > index 4216a18684d..e2027bb9c02 100644
> > --- a/refs/reftable-backend.c
> > +++ b/refs/reftable-backend.c
> > @@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
> >  				    logs[i].value.update.message,
> >  				    policy_cb_data)) {
> >  			dest->value_type = REFTABLE_LOG_DELETION;
> > +			has_changes = true;
> >  		} else {
> > -			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
> > +			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
> > +			    memcmp(dest->value.update.old_hash, last_hash,
> > +				   ref_store->repo->hash_algo->rawsz)) {
> >  				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
> 
> We can skip this second copy.
> 
> > +				has_changes = true;
> > +			}
> >  			last_hash = logs[i].value.update.new_hash;
> >  		}
> >  	}
> >
> > -	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
> > +	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid)) {
> >  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
> > +		if (!oideq(&arg.update_oid, &oid))
> 
> We now check if its changed, makes sense.
> 
> > +			has_changes = true;
> > +	}
> >
> > -	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> > +	if (!has_changes || (flags & EXPIRE_REFLOGS_DRY_RUN)) {
> >  		ret = 0;
> >  		goto done;
> >  	}
> 
> Nit: it would be nice to mention that we exit early to skip writing any
> new tables.

Hm. I thought that this was obvious from the code itself, so I didn't think there was much value in adding a comment. I wouldn't really know what information to put here that doesn't just repeat the code exactly.

Show 39 quoted lines
> > diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
> > index a7027458395..d808f1887f6 100755
> > --- a/t/t0610-reftable-basics.sh
> > +++ b/t/t0610-reftable-basics.sh
> > @@ -912,6 +912,36 @@ test_expect_success 'reflog: expiry empties reflog' '
> >  	)
> >  '
> >
> > +test_expect_success 'reflog: expiry without changes does not write tables' '
> > +	test_when_finished "rm -rf repo" &&
> > +	git init repo &&
> > +	(
> > +		cd repo &&
> > +
> > +		test_commit A &&
> > +		test_commit B &&
> > +		test_commit C &&
> > +		cp .git/reftable/tables.list expect &&
> > +
> > +		git reflog expire --all --expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --rewrite \
> > +			--expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --updateref \
> > +			--expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --dry-run --expire=all &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --expire=all &&
> > +		! test_cmp expect .git/reftable/tables.list
> > +	)
> > +'
> 
> Nice. Could we add a similar test for the previous patch too?

This test also exercises the preceding patch as we use "--dry-run" here. I could've split this up across the two commits, but I was lazy and just added it here.

Patrick
Toon Claes· Nov 18, 2026, 15:34 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op

Patrick Steinhardt <ps@pks.im> writes:
Show 50 quoted lines
> When executing `git reflog expire` we may of course end up not expiring
> any reflog entries because none of them are older than "gc.reflogExpire"
> or "gc.reflogExpireUnreachable". But even so, the reftable backend would
> end up writing a new table to disk anyway that contains basically an
> exact copy of the current reflog. And with the "--all" flag, that would
> happen once per existing reflog. This doesn't result in any correctness
> issues, but it is of course a lot of pointless busywork.
>
> Skip writing and committing the new reftable in the case where there
> aren't any changes, which results in a nice speedup:
>
>   Benchmark 1: git reflog expire --all (commit = HEAD~) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    736.0 ms  ±    11.7 ms     720.0 ms  …   752.3 ms
>     Memory       117.2 MiB ±     0.1 MiB    117.1 MiB …   117.3 MiB
>
>   Benchmark 2: git reflog expire --all (commit = HEAD) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    370.3 ms  ±     3.7 ms     363.4 ms  …   375.6 ms           -49.7%  (2.0x faster)
>     Memory       116.8 MiB ±     0.2 MiB    116.5 MiB …   117.1 MiB           -0.3%
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  refs/reftable-backend.c    | 15 ++++++++++++---
>  t/t0610-reftable-basics.sh | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+), 3 deletions(-)
>
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 4216a18684d..e2027bb9c02 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -2607,6 +2607,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  	struct strbuf referent = STRBUF_INIT;
>  	uint8_t *last_hash = NULL;
>  	size_t logs_nr = 0, logs_alloc = 0, i;
> +	bool has_changes = false;
>  	unsigned int type = 0;
>  	int ret;
>  
> @@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
>  				    logs[i].value.update.message,
>  				    policy_cb_data)) {
>  			dest->value_type = REFTABLE_LOG_DELETION;
> +			has_changes = true;
>  		} else {
> -			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
> +			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
> +			    memcmp(dest->value.update.old_hash, last_hash,
> +				   ref_store->repo->hash_algo->rawsz)) {
>  				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);

I cannot help being bothered by using GIT_MAX_RAWSZ here, and ref_store->repo->hash_algo->rawsz the line above. Would it make sense to be consistent?

-- 
Laters,
Toon
Patrick Steinhardt· Nov 19, 2026, 11:57 UTC · re: Toon Claes · lore

Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op

On Wed, Nov 18, 2026 at 04:34:15PM +0100, Toon Claes wrote:
Show 20 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> > index 4216a18684d..e2027bb9c02 100644
> > --- a/refs/reftable-backend.c
> > +++ b/refs/reftable-backend.c
> > @@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
> >  				    logs[i].value.update.message,
> >  				    policy_cb_data)) {
> >  			dest->value_type = REFTABLE_LOG_DELETION;
> > +			has_changes = true;
> >  		} else {
> > -			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
> > +			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
> > +			    memcmp(dest->value.update.old_hash, last_hash,
> > +				   ref_store->repo->hash_algo->rawsz)) {
> >  				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
> 
> I cannot help being bothered by using GIT_MAX_RAWSZ here, and
> ref_store->repo->hash_algo->rawsz the line above. Would it make sense to
> be consistent?
Fair point, will fix.
Patrick
Patrick Steinhardt· Nov 18, 2026, 09:31 UTC · re: Patrick Steinhardt · lore

[PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"

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

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.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/gc.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
Show changes to builtin/gc.c +21 −12
diff --git a/builtin/gc.c b/builtin/gc.c
index 68cb04a672d..d4a1f337a29 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -282,19 +282,31 @@ static int maintenance_task_pack_refs(struct maintenance_run_opts *opts,
 }
 
 struct count_reflog_entries_data {
-	struct expire_reflog_policy_cb policy;
+	struct reflog_expire_options opts;
 	size_t count;
 	size_t limit;
 };
 
 static int count_reflog_entries(const char *refname UNUSED,
-				struct object_id *old_oid, struct object_id *new_oid,
-				const char *committer, timestamp_t timestamp,
-				int tz, const char *msg, void *cb_data)
+				struct object_id *old_oid UNUSED,
+				struct object_id *new_oid UNUSED,
+				const char *committer UNUSED,
+				timestamp_t timestamp,
+				int tz UNUSED,
+				const char *msg UNUSED,
+				void *cb_data)
 {
 	struct count_reflog_entries_data *data = cb_data;
-	if (should_expire_reflog_ent(old_oid, new_oid, committer, timestamp, tz, msg, &data->policy))
+
+	/*
+	 * We only evaluate whether the entry is older than `gc.reflogExpire`
+	 * and ignore `gc.reflogExpireUnreachable`. Evaluating the latter would
+	 * require a reachability walk, and that's simply too expensive in this
+	 * context.
+	 */
+	if (timestamp < data->opts.expire_total)
 		data->count++;
+
 	return data->count >= data->limit;
 }
 
@@ -302,9 +314,7 @@ static int reflog_expire_condition(struct gc_config *cfg UNUSED)
 {
 	timestamp_t now = time(NULL);
 	struct count_reflog_entries_data data = {
-		.policy = {
-			.opts = REFLOG_EXPIRE_OPTIONS_INIT(now),
-		},
+		.opts = REFLOG_EXPIRE_OPTIONS_INIT(now),
 	};
 	int limit = 100;
 
@@ -315,14 +325,13 @@ static int reflog_expire_condition(struct gc_config *cfg UNUSED)
 		return 1;
 	data.limit = limit;
 
-	repo_config(the_repository, reflog_expire_config, &data.policy.opts);
+	repo_config(the_repository, reflog_expire_config, &data.opts);
 
-	reflog_expire_options_set_refname(&data.policy.opts, "HEAD");
+	reflog_expire_options_set_refname(&data.opts, "HEAD");
 	refs_for_each_reflog_ent(get_main_ref_store(the_repository), "HEAD",
 				 count_reflog_entries, &data);
 
-	reflog_expiry_cleanup(&data.policy);
-	reflog_clear_expire_config(&data.policy.opts);
+	reflog_clear_expire_config(&data.opts);
 	return data.count >= data.limit;
 }
 
-- 
2.56.1.831.g720f3f5937.dirty
Toon Claes· Nov 18, 2026, 15:52 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"

Patrick Steinhardt <ps@pks.im> writes:
Show 24 quoted lines
> 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.

Show 12 quoted lines
> 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.
Show 18 quoted lines
> 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
Patrick Steinhardt· Nov 19, 2026, 11:58 UTC · re: Toon Claes · lore

Re: [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"

On Wed, Nov 18, 2026 at 04:52:45PM +0100, Toon Claes wrote:
Show 31 quoted lines
> 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?

It isn't called, and that's exactly the problem because we need to call it to compute reachability. So we could fix this by starting to call the function, but we instead pick a different route to fix this issue.

Patrick
Patrick Steinhardt· Nov 18, 2026, 09:31 UTC · re: Patrick Steinhardt · lore

[PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto"

In the documentation of "maintenance.reflog-expire.auto" we accidentally refer to "maintenance.loose-objects.auto" instead. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/config/maintenance.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to Documentation/config/maintenance.adoc +1 −1
diff --git a/Documentation/config/maintenance.adoc b/Documentation/config/maintenance.adoc
index 165102518ce..7066fe0e168 100644
--- a/Documentation/config/maintenance.adoc
+++ b/Documentation/config/maintenance.adoc
@@ -116,7 +116,7 @@ maintenance.reflog-expire.auto::
 	negative value will force the task to run every time. Otherwise, a
 	positive value implies the command should run when the number of
 	expired reflog entries in the "HEAD" reflog is at least the value of
-	`maintenance.loose-objects.auto`. The default value is 100.
+	`maintenance.reflog-expire.auto`. The default value is 100.
 
 maintenance.rerere-gc.auto::
 	This integer config option controls how often the `rerere-gc` task
-- 
2.56.1.831.g720f3f5937.dirty
Toon Claes· Nov 18, 2026, 15:54 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto"

Patrick Steinhardt <ps@pks.im> writes:
Show 18 quoted lines
> In the documentation of "maintenance.reflog-expire.auto" we accidentally
> refer to "maintenance.loose-objects.auto" instead. Fix this.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  Documentation/config/maintenance.adoc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/config/maintenance.adoc b/Documentation/config/maintenance.adoc
> index 165102518ce..7066fe0e168 100644
> --- a/Documentation/config/maintenance.adoc
> +++ b/Documentation/config/maintenance.adoc
> @@ -116,7 +116,7 @@ maintenance.reflog-expire.auto::
>  	negative value will force the task to run every time. Otherwise, a
>  	positive value implies the command should run when the number of
>  	expired reflog entries in the "HEAD" reflog is at least the value of
> -	`maintenance.loose-objects.auto`. The default value is 100.
> +	`maintenance.reflog-expire.auto`. The default value is 100.
:) Whoops. Good find.
-- 
Laters,
Toon
Toon Claes· Nov 18, 2026, 15:56 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 0/4] Improve performance of reflog expiration

Patrick Steinhardt <ps@pks.im> writes:
Show 16 quoted lines
> Hi,
>
> I recently noticed that a bunch of commands started hanging for almost a
> second after they're essentially done already. As it turns out, this was
> caused by auto-maintenance, which was blocking in the foreground for
> ~800ms.
>
> The root cause of this is that the auto-condition of "reflog-expire"
> doesn't properly evaluate reachability of reflog entries, so it instead
> considered every single reflog entry to point to an unreachable commit.
> Hence, all entries were evaluated against "gc.reflogExpireUnreachable"
> instead of "gc.reflogExpire", and thus the auto-condition significantly
> overcounts the number of entries that we'd prune. So every single run of
> git-maintenance(1) ultimately ended up spawning `git reflog expire`.
>
> This is fixed by the last patch in this series.
Well, the last one is a doc change, but I get what you mean.
Show 21 quoted lines
> But I was a bit
> surprised that a no-op `git reflog expire` took this long, so the first
> two patches optimize the reftable backend to be more efficient, too.
> In my copy of "git.git":
>
>   Benchmark 1: git maintenance run --auto (commit = master) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    853.2 ms  ±    99.9 ms     570.9 ms  …   901.9 ms
>     Memory       117.5 MiB ±     0.3 MiB    117.2 MiB …   118.2 MiB
>
>   Benchmark 2: git maintenance run --auto (commit = reftable-optimizations) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time    392.3 ms  ±     2.3 ms     388.0 ms  …   396.6 ms           -54.0%  (2.2x faster)
>     Memory       117.2 MiB ±     0.2 MiB    116.8 MiB …   117.4 MiB           -0.2%
>
>   Benchmark 3: git maintenance run --auto (commit = auto-condition-optimizations) (10 runs)
>                   mean     ±       σ          min     …     max
>     Wall Time     18.6 ms  ±     1.1 ms      17.4 ms  …    20.9 ms           -97.8%  (45.8x faster)
>     Memory        81.2 MiB ±     0.1 MiB     80.9 MiB …    81.4 MiB          -30.9%  (1.4x less)
>
> So yeah, it's a bit more efficient now. :)

Great work. I only had one remark on consistency, but not really worth a reroll in itself if you ask me.

-- 
Laters,
Toon
Patrick Steinhardt· Nov 19, 2026, 11:58 UTC · re: Toon Claes · lore

Re: [PATCH 0/4] Improve performance of reflog expiration

On Wed, Nov 18, 2026 at 04:56:57PM +0100, Toon Claes wrote:
Show 20 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > Hi,
> >
> > I recently noticed that a bunch of commands started hanging for almost a
> > second after they're essentially done already. As it turns out, this was
> > caused by auto-maintenance, which was blocking in the foreground for
> > ~800ms.
> >
> > The root cause of this is that the auto-condition of "reflog-expire"
> > doesn't properly evaluate reachability of reflog entries, so it instead
> > considered every single reflog entry to point to an unreachable commit.
> > Hence, all entries were evaluated against "gc.reflogExpireUnreachable"
> > instead of "gc.reflogExpire", and thus the auto-condition significantly
> > overcounts the number of entries that we'd prune. So every single run of
> > git-maintenance(1) ultimately ended up spawning `git reflog expire`.
> >
> > This is fixed by the last patch in this series.
> 
> Well, the last one is a doc change, but I get what you mean.

Oops, true, this one is stale. I only added that last commit after having written the cover letter.

Patrick

← back to recent threads