Git development
 help / color / mirror / Atom feed
* [PATCH 0/4] Improve performance of reflog expiration
@ 2026-11-18  9:30 Patrick Steinhardt
  2026-11-18  9:31 ` [PATCH 1/4] refs/reftable: don't write new table on dry-run expire Patrick Steinhardt
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18  9:30 UTC (permalink / raw)
  To: git

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/4] refs/reftable: don't write new table on dry-run expire
  2026-11-18  9:30 [PATCH 0/4] Improve performance of reflog expiration Patrick Steinhardt
@ 2026-11-18  9:31 ` Patrick Steinhardt
  2026-11-18 11:28   ` Karthik Nayak
  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
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18  9:31 UTC (permalink / raw)
  To: git

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

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op
  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  9:31 ` Patrick Steinhardt
  2026-11-18 11:33   ` Karthik Nayak
  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
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18  9:31 UTC (permalink / raw)
  To: git

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);
+				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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"
  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  9:31 ` [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op Patrick Steinhardt
@ 2026-11-18  9:31 ` Patrick Steinhardt
  2026-11-18 15:52   ` Toon Claes
  2026-11-18  9:31 ` [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto" Patrick Steinhardt
  2026-11-18 15:56 ` [PATCH 0/4] Improve performance of reflog expiration Toon Claes
  4 siblings, 1 reply; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18  9:31 UTC (permalink / raw)
  To: git

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

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto"
  2026-11-18  9:30 [PATCH 0/4] Improve performance of reflog expiration Patrick Steinhardt
                   ` (2 preceding siblings ...)
  2026-11-18  9:31 ` [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto" Patrick Steinhardt
@ 2026-11-18  9:31 ` Patrick Steinhardt
  2026-11-18 15:54   ` Toon Claes
  2026-11-18 15:56 ` [PATCH 0/4] Improve performance of reflog expiration Toon Claes
  4 siblings, 1 reply; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18  9:31 UTC (permalink / raw)
  To: git

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.
 
 maintenance.rerere-gc.auto::
 	This integer config option controls how often the `rerere-gc` task

-- 
2.56.1.831.g720f3f5937.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire
  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
  1 sibling, 1 reply; 14+ messages in thread
From: Karthik Nayak @ 2026-11-18 11:28 UTC (permalink / raw)
  To: Patrick Steinhardt, git

[-- Attachment #1: Type: text/plain, Size: 2492 bytes --]

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.
>
> 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.

> 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.

>  done:
>  	if (add)
>
> --
> 2.56.1.831.g720f3f5937.dirty

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op
  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
  1 sibling, 1 reply; 14+ messages in thread
From: Karthik Nayak @ 2026-11-18 11:33 UTC (permalink / raw)
  To: Patrick Steinhardt, git

[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]

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
> @@ -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.

> +				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.

> 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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire
  2026-11-18 11:28   ` Karthik Nayak
@ 2026-11-18 12:05     ` Patrick Steinhardt
  0 siblings, 0 replies; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18 12:05 UTC (permalink / raw)
  To: Karthik Nayak; +Cc: git

On Wed, Nov 18, 2026 at 03:28:25AM -0800, Karthik Nayak wrote:
> 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op
  2026-11-18 11:33   ` Karthik Nayak
@ 2026-11-18 12:05     ` Patrick Steinhardt
  0 siblings, 0 replies; 14+ messages in thread
From: Patrick Steinhardt @ 2026-11-18 12:05 UTC (permalink / raw)
  To: Karthik Nayak; +Cc: git

On Wed, Nov 18, 2026 at 03:33:04AM -0800, Karthik Nayak wrote:
> 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.

> > 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op
  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 15:34   ` Toon Claes
  1 sibling, 0 replies; 14+ messages in thread
From: Toon Claes @ 2026-11-18 15:34 UTC (permalink / raw)
  To: Patrick Steinhardt, git

Patrick Steinhardt <ps@pks.im> writes:

> 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto"
  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
  0 siblings, 0 replies; 14+ messages in thread
From: Toon Claes @ 2026-11-18 15:52 UTC (permalink / raw)
  To: Patrick Steinhardt, git

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto"
  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
  0 siblings, 0 replies; 14+ messages in thread
From: Toon Claes @ 2026-11-18 15:54 UTC (permalink / raw)
  To: Patrick Steinhardt, git

Patrick Steinhardt <ps@pks.im> writes:

> 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/4] Improve performance of reflog expiration
  2026-11-18  9:30 [PATCH 0/4] Improve performance of reflog expiration Patrick Steinhardt
                   ` (3 preceding siblings ...)
  2026-11-18  9:31 ` [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto" Patrick Steinhardt
@ 2026-11-18 15:56 ` Toon Claes
  4 siblings, 0 replies; 14+ messages in thread
From: Toon Claes @ 2026-11-18 15:56 UTC (permalink / raw)
  To: Patrick Steinhardt, git

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.

> 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] refs/reftable: don't write new table on dry-run expire
  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 16:51   ` Junio C Hamano
  1 sibling, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2026-11-18 16:51 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git

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?

> 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)

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-11-18 16:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox