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

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

From
Jeff King <peff@peff.net>
Date
Jul 18, 2026, 08:14 UTC
Message-ID
<20260718081407.GC22588@coredump.intra.peff.net>
In-Reply-To
<87a4rp1l65.fsf@emacs.iotcl.com>
On Fri, Jul 17, 2026 at 09:16:34PM +0200, Toon Claes wrote:
Show 13 quoted lines
> > +	/*
> > +	 * 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);
> > +
> 
> @Peff, as far I could tell:
> 
> * This change was not needed to be able to use the Bloom filters with
>   the pathspec.

Ah, right. In my earlier attempt I came at it from the bottom up: I found the bloom_keyvec, saw how it was populated, and then worked my way back to prepare_to_use_bloom_filter() without going further.

But it is much nicer if we can rely on prepare_revision_walk() here, as we don't need to make an additional function public.

> * Only restoring bloom_filter_settings was needed. In your patch you're
>   calling prepare_to_use_bloom_filter(), but that is being called by
>   prepare_revision_walk(). Thus the restoring of the filter settings
>   I've added after that function.

Hmm, OK. The "clearing" done by prepare_revision_walk() is kind of weird. The bloom settings are a const pointer, not a resource we own, so there is really no need to clear them.

But accepting for a moment that we do clear them, is this maybe an indication that we are abusing rev_info.bloom_filter_settings? It is really an internal implementation detail that revision.c uses for its own bloom filters. Wouldn't it be cleaner for last-modified to keep its own, like this:

diff --git a/builtin/last-modified.c b/builtin/last-modified.c
index fe012b0c2e..5e176bbeed 100644
--- a/builtin/last-modified.c
+++ b/builtin/last-modified.c
@@ -61,6 +61,8 @@ struct last_modified {
 	size_t all_paths_nr;
 	struct active_paths_for_commit active_paths;
 
+	struct bloom_filter_settings *bloom_filter_settings;
+
 	/* 'scratch' to avoid allocating a bitmap every process_parent() */
 	struct bitmap *scratch;
 };
@@ -114,9 +116,9 @@ static void add_path_from_diff(struct diff_queue_struct *q,
 
 		FLEX_ALLOC_STR(ent, path, path);
 		oidcpy(&ent->oid, &p->two->oid);
-		if (lm->rev.bloom_filter_settings)
+		if (lm->bloom_filter_settings)
 			bloom_key_fill(&ent->key, path, strlen(path),
-				       lm->rev.bloom_filter_settings);
+				       lm->bloom_filter_settings);
 		hashmap_entry_init(&ent->hashent, strhash(ent->path));
 		hashmap_add(&lm->paths, &ent->hashent);
 	}
@@ -262,7 +264,7 @@ static bool maybe_changed_path(struct last_modified *lm,
 	struct last_modified_entry *ent;
 	struct hashmap_iter iter;
 
-	if (!lm->rev.bloom_filter_settings)
+	if (!lm->bloom_filter_settings)
 		return true;
 
 	if (commit_graph_generation(origin) == GENERATION_NUMBER_INFINITY)
@@ -277,7 +279,7 @@ static bool maybe_changed_path(struct last_modified *lm,
 			continue;
 
 		if (bloom_filter_contains(filter, &ent->key,
-					  lm->rev.bloom_filter_settings))
+					  lm->bloom_filter_settings))
 			return true;
 	}
 	return false;
@@ -502,7 +504,7 @@ static int last_modified_init(struct last_modified *lm, struct repository *r,
 		return argc;
 	}
 
-	lm->rev.bloom_filter_settings = get_bloom_filter_settings(lm->rev.repo);
+	lm->bloom_filter_settings = get_bloom_filter_settings(lm->rev.repo);
 
 	if (populate_paths_from_revs(lm) < 0)
 		return -1;

It's mostly academic, as both of the pointers (if not NULL) would always
point to the same setting that ultimately come from the repository
object. But it feels cleaner for them to keep their own pointers,
because that pointer may also signal "do we have usable bloom filters".
We are a little lucky in dodging a bug here: last-modified uses the
pointer for that purpose, but if revision.c did so also, they'd
conflict.

  Side note: this is really a repository property, so it would be nice
  if we could just do:

    repo_bloom_filter_contains(filter, &ent->key);

  without managing the settings pointer ourselves at all. But the cost
  to fetch it from the graph linked list is not totally trivial, so we'd
  probably end up having to cache it somewhere. I don't know if that's
  worth it (plus last-modified would still have to keep a boolean
  somewhere to decide whether it is using bloom filters or not).

-Peff
Previous: Toon ClaesNext: Junio C Hamano
Message 16 of 30 in “last-modified: use the pathspec's Bloom key to pre-filter commits”
  1. 0/4 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Jul 17, 2026
  2. 1/4 revision: move bloom keyvec precondition into functionToon Claes, Jul 17, 2026
  3. Jeff KingJul 18, 2026
  4. Toon ClaesAug 5, 2026
  5. Jeff KingAug 5, 2026
  6. 2/4 revision: expose check for paths maybe changed in Bloom filterToon Claes, Jul 17, 2026
  7. Junio C HamanoJul 17, 2026
  8. Taylor BlauJul 17, 2026
  9. 3/4 last-modified: check pathspec against Bloom filter firstToon Claes, Jul 17, 2026
  10. Taylor BlauJul 17, 2026
  11. Jeff KingJul 18, 2026
  12. Taylor BlauJul 18, 2026
  13. Jeff KingJul 20, 2026
  14. 4/4 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Jul 17, 2026
  15. Toon ClaesJul 17, 2026
  16. Jeff KingJul 18, 2026
  17. Junio C HamanoAug 4, 2026
  18. Taylor BlauAug 5, 2026
  19. Junio C HamanoAug 5, 2026
  20. Jeff KingAug 5, 2026
  21. Taylor BlauJul 17, 2026
  22. Toon ClaesJul 17, 2026
  23. 0/6 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Aug 7, 2026
  24. 1/6 revision: move bloom keyvec precondition into functionToon Claes, Aug 7, 2026
  25. 2/6 revision: expose check for paths maybe changed in Bloom filterToon Claes, Aug 7, 2026
  26. 3/6 bloom: add helper to check if any key in a vector is presentToon Claes, Aug 7, 2026
  27. 4/6 revision: add Bloom check that includes parent directoriesToon Claes, Aug 7, 2026
  28. 5/6 last-modified: check pathspec against Bloom filter firstToon Claes, Aug 7, 2026
  29. 6/6 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Aug 7, 2026
  30. Junio C HamanoAug 8, 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.