git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:00 UTC

[PATCH v3 6/6] last-modified: keep per-path Bloom filters for wildcard pathspecs

From
Toon Claes <toon@iotcl.com>
Date
Aug 31, 2026, 15:18 UTC
Message-ID
<20260831-toon-speed-up-last-modified-v3-6-2bbb864acf93@iotcl.com>
In-Reply-To
<20260831-toon-speed-up-last-modified-v3-0-2bbb864acf93@iotcl.com>

The last-modified builtin expands the pathspec to a set of literal paths and builds a Bloom key for each. During the walk it looks those keys up in the commit's filter to decide whether the commit is worth diffing. These lookups need `bloom_filter_settings` for the key hashing.

prepare_revision_walk() runs prepare_to_use_bloom_filter() to build the pathspec key vectors. For a pathspec that cannot be turned into a Bloom key, such as a top-level wildcard like "*.c", that function gives up and clears `bloom_filter_settings`.

Restore `bloom_filter_settings` after prepare_revision_walk() so the per-path check keeps working for wildcard pathspecs.

This change isn't having any effect on the output, but only has an impact on performance. Add a "bloom_queries" trace2 counter that records how often the per-path Bloom check runs, and a test that asserts the count increments as appropriate for a top-level wildcard pathspec.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 builtin/last-modified.c  | 16 ++++++++++++++++
 t/t8020-last-modified.sh | 26 ++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
diff --git a/builtin/last-modified.c b/builtin/last-modified.c
index 8ab7944314..bedccb3ace 100644
--- a/builtin/last-modified.c
+++ b/builtin/last-modified.c
@@ -18,6 +18,7 @@
 #include "quote.h"
 #include "repository.h"
 #include "revision.h"
+#include "trace2.h"
 
 /* Remember to update object flag allocation in object.h */
 #define PARENT1 (1u<<16) /* used instead of SEEN */
@@ -63,6 +64,8 @@ struct last_modified {
 
 	/* 'scratch' to avoid allocating a bitmap every process_parent() */
 	struct bitmap *scratch;
+
+	unsigned int count_bloom_filter_queries;
 };
 
 static struct bitmap *active_paths_for(struct last_modified *lm, struct commit *c)
@@ -272,6 +275,8 @@ static bool maybe_changed_path(struct last_modified *lm,
 	if (!filter)
 		return true;
 
+	lm->count_bloom_filter_queries++;
+
 	/*
 	 * With --show-trees we also track the tree entries containing the
 	 * paths, so a change to any of those parent directories matters too.
@@ -370,6 +375,14 @@ static int last_modified_run(struct last_modified *lm)
 
 	prepare_revision_walk(&lm->rev);
 
+	/*
+	 * prepare_revision_walk() clears bloom_filter_settings for pathspecs
+	 * without a Bloom key. Restore it so the per-path check keeps working.
+	 */
+	if (!lm->rev.bloom_filter_settings)
+		lm->rev.bloom_filter_settings =
+			get_bloom_filter_settings(lm->rev.repo);
+
 	max_count = lm->rev.max_count;
 
 	init_active_paths_for_commit(&lm->active_paths);
@@ -479,6 +492,9 @@ static int last_modified_run(struct last_modified *lm)
 	if (hashmap_get_size(&lm->paths))
 		BUG("paths remaining beyond boundary in last-modified");
 
+	trace2_data_intmax("last-modified", lm->rev.repo, "bloom_queries",
+			   lm->count_bloom_filter_queries);
+
 	clear_prio_queue(&not_queue);
 	clear_prio_queue(&queue);
 	clear_active_paths_for_commit(&lm->active_paths);
diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh
index df73c7d0d0..75b18ee83b 100755
--- a/t/t8020-last-modified.sh
+++ b/t/t8020-last-modified.sh
@@ -290,6 +290,32 @@ test_expect_success 'last-modified with Bloom filters and --show-trees' '
 	)
 '
 
+test_expect_success 'last-modified with Bloom filters and top-level wildcard' '
+	test_when_finished rm -rf wildcard &&
+	git init wildcard &&
+	(
+		cd wildcard &&
+		test_commit base-c a.c &&
+		test_commit base-h a.h &&
+		test_commit touch-c a.c &&
+		mkdir d &&
+		test_commit sub-c d/b.c &&
+
+		git commit-graph write --reachable --changed-paths &&
+		GIT_TRACE2_PERF="$(pwd)/off.perf" \
+			git -c core.commitGraph=false last-modified -r HEAD \
+			-- "*.c" >expect &&
+		test_grep "data .* bloom_queries:0$" off.perf &&
+
+		GIT_TRACE2_PERF="$(pwd)/on.perf" \
+			git -c core.commitGraph=true last-modified -r HEAD \
+			-- "*.c" >actual &&
+		test_grep "data .* bloom_queries:2$" on.perf &&
+
+		test_cmp expect actual
+	)
+'
+
 test_expect_success 'cannot run last-modified on two commits' '
 	test_must_fail git last-modified HEAD HEAD~1 2>err &&
 	test_grep "last-modified can only operate on one commit at a time" err
-- 
2.55.0.679.g6767b8d81c
Previous: Toon ClaesNext: Junio C Hamano
Message 7 of 22 in “revision: move bloom keyvec precondition into function”
  1. 1/6 revision: move bloom keyvec precondition into functionToon Claes, Aug 31, 2026
  2. 2/6 revision: expose check for paths maybe changed in Bloom filterToon Claes, Aug 31, 2026
  3. 0/6 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Aug 31, 2026
  4. 3/6 bloom: add helper to check if any key in a vector is presentToon Claes, Aug 31, 2026
  5. 4/6 revision: add Bloom check that includes parent directoriesToon Claes, Aug 31, 2026
  6. 5/6 last-modified: check pathspec against Bloom filter firstToon Claes, Aug 31, 2026
  7. 6/6 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Aug 31, 2026
  8. Junio C HamanoAug 31, 2026
  9. Junio C HamanoSep 1, 2026
  10. Toon ClaesSep 1, 2026
  11. 0/6 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Sep 1, 2026
  12. 1/6 revision: move bloom keyvec precondition into functionToon Claes, Sep 1, 2026
  13. 2/6 revision: expose check for paths maybe changed in Bloom filterToon Claes, Sep 1, 2026
  14. 3/6 bloom: add helper to check if any key in a vector is presentToon Claes, Sep 1, 2026
  15. 4/6 revision: add Bloom check that includes parent directoriesToon Claes, Sep 1, 2026
  16. 5/6 last-modified: check pathspec against Bloom filter firstToon Claes, Sep 1, 2026
  17. 6/6 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Sep 1, 2026
  18. Junio C HamanoSep 1, 2026
  19. Patrick SteinhardtSep 10, 2026
  20. Patrick SteinhardtSep 10, 2026
  21. Patrick SteinhardtSep 10, 2026
  22. Patrick SteinhardtSep 10, 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.