From: Patrick Steinhardt <ps@pks.im>
To: Andy Koppe <andy.koppe@gmail.com>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH] refs/files: keep root refs out of loose ref cache
Date: Thu, 15 Oct 2026 07:58:01 +0200 [thread overview]
Message-ID: <atBraYoY1SVwnezN@pks.im> (raw)
In-Reply-To: <20261014153208.2194727-1-andy.koppe@gmail.com>
On Wed, Oct 14, 2026 at 04:32:08PM +0100, Andy Koppe wrote:
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 71628550f2..74409878b6 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -481,8 +481,21 @@ static void add_root_refs(struct files_ref_store *refs,
> for_each_root_ref(refs, fill_root_ref, &data);
> }
>
> -static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs,
> - unsigned int flags)
> +/*
> + * Create a separate ref cache containing only the root refs. These are kept
> + * out of the loose ref cache, which may already exist and is shared by
> + * iterations that should not include them.
> + */
This raises the question whether an alternative fix could have been to
teach the cache itself to skip over root refs in case the caller is not
interested in them. The answer may very well be a "no", but I would be
curious to learn why you settled on the proposed fix instead.
> +static struct ref_cache *create_root_ref_cache(struct files_ref_store *refs)
> +{
> + struct ref_cache *cache = create_ref_cache(&refs->base, NULL);
> +
> + cache->root->flag &= ~REF_INCOMPLETE;
> + add_root_refs(refs, get_ref_dir(cache->root));
> + return cache;
> +}
> +
> +static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
> {
> if (!refs->loose) {
> struct ref_dir *dir;
> @@ -1094,9 +1107,17 @@ static struct ref_iterator *files_ref_iterator_begin(
> * disk, and re-reads it if not.
> */
>
> - loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, flags),
> + loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
> prefix, ref_store->repo, 1);
>
> + if (flags & REFS_FOR_EACH_INCLUDE_ROOT_REFS) {
> + root_refs = create_root_ref_cache(refs);
> + loose_iter = overlay_ref_iterator_begin(
> + cache_ref_iterator_begin(root_refs, prefix,
> + ref_store->repo, 0),
> + loose_iter);
> + }
It's a bit weird that we recreate the root ref "cache" for every single
ref iterator we create that asks for root refs. Is there a reason why
you have decided to not actually cache the root refs the same way as we
cache the loose refs?
Thanks!
Patrick
next prev parent reply other threads:[~2026-10-15 5:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 15:32 [PATCH] refs/files: keep root refs out of loose ref cache Andy Koppe
2026-10-15 5:58 ` Patrick Steinhardt [this message]
2026-10-15 17:31 ` Junio C Hamano
2026-10-15 19:43 ` Andy Koppe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atBraYoY1SVwnezN@pks.im \
--to=ps@pks.im \
--cc=andy.koppe@gmail.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.