🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #627

Re: [PATCH] refs/files: keep root refs out of loose ref cache

#627
From: Andy Koppe
Date: Thu, 15 Oct 2026 19:43
57 lines
11439 bytes
Junio C Hamano <gitster@pobox.com> wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>>> +/*
>>> + * 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.
>> ...
>>> -    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?
>
> Curious.
>
> So an alternative would be to have two caches, the primary one for
> things under refs/ hierarchy and the other one for those outside,
> and callers can choose to use only the primary one or use both of
> them?

Thanks for considering this.

I think it makes for a simpler change with less overhead to not
actually cache them, as there are only two uses of the
REFS_FOR_EACH_INCLUDE_ROOT_REFS flag: in builtin/for-each-ref.c for
`git for-each-ref --include-root-refs`, and in builtin/refs.c for `git
refs migrate`. And both only invoke it once.

I considered keeping the root refs in the loose ref cache but skipping
them during iteration if the flag is unset. But that would mean more
impact on that much more common case.

A cleaner approach might be to drop the flag and change all call sites
that currently ask for all refs without setting the flag, so that they
explicitly ask for "refs/" only. That way root refs wouldn't need as
much special handling. But of course that would be a much bigger and
more risky change.

Andy
Technical Details
Message-ID: <CAHWeT-Z4n=txTGaBNuGPj3jcOou91owB59gvaPvF=2_p50eFHA@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72176-linux-kernel-git=dewy.ru
References: <20261014153208.2194727-1-andy.koppe@gmail.com> <atBraYoY1SVwnezN@pks.im> <xmqqmrseooor.fsf@gitster.g>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72176-linux-kernel-git=dewy.ru
From: andy.koppe@gmail.com (Andy Koppe)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH] refs/files: keep root refs out of loose ref cache
Date: Thu, 15 Oct 2026 20:43:06 +0100
Organization: Usenet Network
Message-ID: <CAHWeT-Z4n=txTGaBNuGPj3jcOou91owB59gvaPvF=2_p50eFHA@mail.gmail.com>
References: <20261014153208.2194727-1-andy.koppe@gmail.com>
 <atBraYoY1SVwnezN@pks.im> <xmqqmrseooor.fsf@gitster.g>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: usenet.network;
	logging-data="2606775"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0o6cpwoIIevuEelWabhcY2RsQws= sha256:vLqQvnq6CPjeZEqm0YOg8BMAU0sfL7E9BOch1sO32qw=
	sha1:lalTkbsMmmu9DxPIA4zWqMAWxVs= sha256:tn7yS3nwcvDjw86g74r0/1Je8BEkNjdkYYSFH6m7+w4=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1AC521103BA; Thu, 15 Oct 2026 22:43:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id vLPsYtUVhQfu;
	Thu, 15 Oct 2026 22:43:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72176-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 69769110200; Thu, 15 Oct 2026 22:43:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id 7E4BA3B4A8; Thu, 15 Oct 2026 19:43:23 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 70B753E1D02;
	Thu, 15 Oct 2026 19:43:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bfa0o3fM"
X-Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBEC33E7640
	for <git@vger.kernel.org>; Thu, 15 Oct 2026 19:43:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.161.43
X-ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792093401; cv=pass; b=Nd0ttsbVl+ygbuYpaDBn6CvMBijc9PPRK2zhgIG1MQghmqTTOY/soGHBnAxL1KykOD6mm2cRYBknkA6iG7pdwVUKt2JUEMxw218jPVlj6W/RGf8Dq35f7vNA7aDM0xC5uB8EJYjjvtJwyQtQDeGLDpQUrZBIRIqkarVBHeJpNlU=
X-ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792093401; c=relaxed/simple;
	bh=t8DPzbjSzZh5PNJyLUMAaIkwjJn8uM/67cW4jXSNEPA=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=AMdLIimbC3CZzhSOiZCbLlTtuqO2UWvJGMJ0TXEaBC4T43pJvgDLiNFaT9uG9bJIdn6sUe4CkbQR6J22VYZmJCTpaLHY8DfsMQlORPgptGFpPf30DnTsLy6cpsxSZ9kvNXU/zR/9BNdVh8rZzlyPMuDz2L26BGi5oI2AIg4NPd0=
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bfa0o3fM; arc=pass smtp.client-ip=209.85.161.43
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-6de1ca1b05aso3760568eaf.0
        for <git@vger.kernel.org>; Thu, 15 Oct 2026 12:43:19 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1792093399; cv=none;
        d=google.com; s=arc-20260327;
        b=Qwp0+SbfoJLwH+zH6o4i9Wq7/KB0zRdx063LC7uAAJXBDvLA0vQctmAZjEMKyGXtgZ
         HpeTvGSOxmijXyVmJW02BjOC5YshacrawuhQRRYkgxD7mDQlLVY3RbEwwlcBvhaWObKy
         ysDCIupcvI0BlZmou89COQQp1vNJmFGHYWaDd3ARfn0mABvRosP9GiVgoVKkih+nKw+f
         wJnTmYj8tfdwtyryIhNuquv+1T08MI8fAQZ2OCNkRT/W620WmdRhiqTli1ZmUFVr9Pi4
         kEZW0PWTIJmC2pKI663uCDk4SAOR5L/0aJm/VJY6UP+zIE5JTp4nufFyaKPsa3VOv8rO
         8tug==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
        h=cc:to:subject:message-id:date:from:in-reply-to:references
         :mime-version:dkim-signature;
        bh=utlTfKViyjBzy8R8woSxA1BTcHpgztw0a668U3yPORk=;
        fh=G0JnDLNJP0BpiWLSj76ohlq/MxrD0p4yG2Eg1RehNyo=;
        b=ERSd0fcEkAnGij7D4EcATQVgXyFXqSQMW9brmgESo20WVxlmJYVVo/okp1eTESnp1n
         791WxO1YgCFxUM3hxiWZf0tH2mYroLjjliQyZr8eHRJRGXOsvPJZd9n5Pv+O1BBGLeh8
         q1adG0GmyaxlixXgcapPgWW/CGQfwM4mH+Vpe8g9V7x/r6ECMdOtjzW1M46chTKgUODI
         N071+yc0Kud2xoTPvgY94OjlXxPgnxHCQKVYkp9pgdWqf+47jIK54ohrQKOIWH0xGTK3
         b/wrQubBsvOT6vHca2+tU3TNTuZjKc0henxBWLZHBtxJ7zjBYoSs566VPxvtdkIemjMo
         ADSw==;
        darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792093399; x=1792698199; darn=vger.kernel.org;
        h=content-type:cc:to:subject:message-id:date:from:in-reply-to
         :references:mime-version:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=utlTfKViyjBzy8R8woSxA1BTcHpgztw0a668U3yPORk=;
        b=Bfa0o3fMY7ASB1bSACv1tNhkLDesM/CM7E3jhnbpIVckFgAVQ5bxAsLLk6yIZdjpg+
         DyHVc9QD9AfXSr94wwj6EMLhH4l9gWSoZbnPXdUtL6SoU+d//l+l4qWbBXIyqEqM4SIM
         MXDYUbF918A8q9suWeJL06OFEVHB4DFEB1eIzqodMFhlJbzIzfObMLUjCmP9Kngxq3wL
         7SnhJcvREjOPHDNBMIHGoInM2qykwvuDA52tYIOdDUFDiDZBdgCYuY2C0OTiXa2TCUH9
         ykVvbIrX7nV6NOCuIEh83xStSDA7GLlI8VjkvJ0q/kqbPmAZuHHHhuXDMjAhCgY/flRf
         89jg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792093399; x=1792698199;
        h=content-type:cc:to:subject:message-id:date:from:in-reply-to
         :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=utlTfKViyjBzy8R8woSxA1BTcHpgztw0a668U3yPORk=;
        b=HcY2tXeRrQtaJZ7wWuTaQMMRj6nXSu8lwvPPCq5sTfdPp1g9KwZ2ZfhR+Q1nxEt/Pp
         gxHm8rAeAAJCdzSqCULQy75n+hcUz1IAIY+gF0CcgPKTZDBIr3sQE1tUxlGjwQtUi8gD
         /jko3oqFI/I8uf0yzzLSUDL6i6PEhWfqPIm6PiZ9dsKDemcqgveXrCeOd2wSiTcjX1iU
         Lau+vPyQCNhFsYiJcB8xaT13O0SOvRAH6q2pgBfyVenpsfU1W9jQIoaxiAnk7ONQv0Xw
         EKkDMpts3qDGW/dJl9yBHABmA5c1r3Is9wGBkARCnqpw0xmELWtBztUnlXf7PqYCbig/
         tDAQ==
X-Forwarded-Encrypted: i=1; AKwUvBzLxHzYVa+qDCi2UxB3fdFUVSOPAbYbNtiEmwOeyx7eAaZ+Gll0dGU1Gd6tI8EieGVJ1jg=@vger.kernel.org
X-Gm-Message-State: AFq9FYKZDqfZeesGrygozS7g3f6NjD5xdnmbFrNPJ0x3aSJU+SfpqJaG
	V0/tlpFTlAlrpaAq30mPejZtQ8wenBaRlXEv55X36SeBk99/WTPJyRRcwBpoC2unolUoDrJfqfP
	0ydoh2E1ib6tWFYgjHUz64++hVjFGTdQ=
X-Gm-Gg: AYBFou32dD6P5o9vgXyveFEKEXtvF5rKd+cwrIUnCEIETvVLMVNBKJkNw3tyNvOo9IO
	9GNvh+NOQI8L8YX37Njn4qDg8+60YoZI4nZa23AYDp3GKlJWUY12ikyvBi8ZzcLn7Un5IVeHAGX
	5UqogsHCmliomSQzPeqfx0DpdDgwmio8Qa6KZtPt59eoOiJWJ6zy+QTBpQc0v+4os7iYJ3iNabO
	I5HBZrJ7s2X+EAAa11iFyzqTqlzIy5tPxM4v1FWOdNQdDiNUH+hdPxdeFOB3i1Q/V8een4H04kX
	doLKA5OI1ZgsxcWRzl5AysGqutN6eWRVbUS8WxFRI+VFK6XErdqXEg==
X-Received: by 2002:a05:6820:1986:b0:6de:ba4f:af00 with SMTP id
 006d021491bc7-6ef10295693mr16200260eaf.63.1792093398378; Thu, 15 Oct 2026
 12:43:18 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-In-Reply-To: <xmqqmrseooor.fsf@gitster.g>
X-Gm-Features: AclHuK-3KqvlG_xs4lairvuSURD8bPLsXEeNVrRJUL5CrDvKHPXmjHY21qs9pbM
X-Cc: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>