git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 2, 2026, 08:45 UTC
Message-ID
<20261202-pks-reflog-expire-performance-v2-1-17b2d6dd4867@pks.im>
In-Reply-To
<20261202-pks-reflog-expire-performance-v2-0-17b2d6dd4867@pks.im>

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. That table won't get committed of course, and we unlink it again via `reftable_addition_destroy()`. But it is of course rather pointless to write the data to disk only to unlink it again.

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.98.0.rc0.245.g55e557da3a.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 20 of 24 in “Improve performance of reflog expiration”
  1. 0/4 Improve performance of reflog expirationPatrick Steinhardt, Nov 18, 2026
  2. 1/4 refs/reftable: don't write new table on dry-run expirePatrick Steinhardt, Nov 18, 2026
  3. Karthik NayakNov 18, 2026
  4. Patrick SteinhardtNov 18, 2026
  5. Junio C HamanoNov 18, 2026
  6. Patrick SteinhardtNov 19, 2026
  7. 2/4 refs/reftable: don't write new table when expire is a no-opPatrick Steinhardt, Nov 18, 2026
  8. Karthik NayakNov 18, 2026
  9. Patrick SteinhardtNov 18, 2026
  10. Toon ClaesNov 18, 2026
  11. Patrick SteinhardtNov 19, 2026
  12. 3/4 builtin/maintenance: only consider `gc.reflogExpire` for "--auto"Patrick Steinhardt, Nov 18, 2026
  13. Toon ClaesNov 18, 2026
  14. Patrick SteinhardtNov 19, 2026
  15. 4/4 Documentation/config: fix typo in "maintenance.reflog-expire.auto"Patrick Steinhardt, Nov 18, 2026
  16. Toon ClaesNov 18, 2026
  17. Toon ClaesNov 18, 2026
  18. Patrick SteinhardtNov 19, 2026
  19. 0/4 Improve performance of reflog expirationPatrick Steinhardt, Dec 2, 2026
  20. 1/4 refs/reftable: don't write new table on dry-run expirePatrick Steinhardt, Dec 2, 2026
  21. 2/4 refs/reftable: don't write new table when expire is a no-opPatrick Steinhardt, Dec 2, 2026
  22. 3/4 builtin/maintenance: only consider `gc.reflogExpire` for "--auto"Patrick Steinhardt, Dec 2, 2026
  23. Toon ClaesDec 3, 2026
  24. 4/4 Documentation/config: fix typo in "maintenance.reflog-expire.auto"Patrick Steinhardt, Dec 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.