git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Jeff King <peff@peff.net>
Cc: Dhruva Krishnamurthy <dhruvakm@gmail.com>,
	John Cai <johncai86@gmail.com>,
	Karthik Nayak <karthik.188@gmail.com>,
	git@vger.kernel.org
Subject: Re: using tree as attribute source is slow, was Re: Help troubleshoot performance regression cloning with depth: git 2.44 vs git 2.42
Date: Wed, 1 May 2024 20:33:52 -0400	[thread overview]
Message-ID: <ZjLfcCxjLq4o7hpw@nand.local> (raw)
In-Reply-To: <20240501220030.GA1442509@coredump.intra.peff.net>

On Wed, May 01, 2024 at 06:00:30PM -0400, Jeff King wrote:
> Bisecting show the culprit is 2386535511 (attr: read attributes from
> HEAD when bare repo, 2023-10-13), which is in v2.43.0. Before that, a
> bare repository would only look for attributes in the info/attributes
> file. But after, we look at the HEAD tree-ish, too. And pack-objects
> will check the "delta" attribute for every path of every object we are
> packing. And remember that in-tree lookups for foo/bar/baz require
> looking not just for .gitattributes, but also foo/.gitattributes,
> foo/bar/.gitattributes, and foo/bar/baz/.gitattributes.

Thanks for the explanation and bisection. I agree that 2386535511 makes
sense as a likely culprit given what you wrote here.

>   - the problem doesn't show up if the repo has reachability bitmaps.
>     This is because the bitmap result doesn't have the pathnames of each
>     object (we do have the "name hash", but it's not enough for us to do
>     an attr lookup), and so objects we get from a bitmap do not
>     respect the delta attribute at all.
>
>     But when doing a shallow clone, we have to disable bitmaps and do a
>     regular traversal. So even if you have bitmaps, you still run into
>     the problem.
>
>     The example above should not have bitmaps (we do build them by
>     default when repacking bare repos these days, but I don't think
>     we'll do so right after cloning). If you have a local repo that
>     already has bitmaps, you should be able to see the difference by
>     using "git -c pack.usebitmaps=false pack-objects".

Yikes. I was hoping that bitmaps would be a saving grace here for setups
that have bitmap generation enabled, but it makes sense that it doesn't
help if you are doing a shallow clone where you have to disable bitmaps.

>     So even if you are a server which generally enables bitmaps, you can
>     still get bit by this for shallow clones, but also for other
>     non-bitmap invocations, like say "git repack -ad". There I see the
>     same 3-minute slowdown in the enumeration phase.

That's also pretty scary, and a worthwhile callout.

> So what to do? It seems like some kind of caching would help here. We're
> looking up the same paths over and over, for two reasons:
>
>   1. We'll have many objects with the same paths, one for each time the
>      path was modified through history.
>
>   2. Adjacent objects share the higher-level lookups. Both "dir/a" and
>      "dir/b" will need to look up "dir/.gitattributes" (and all the way
>      up to ".gitattributes").

Right. I guess you need to cache something like on the order of the set
of dirnames of all modified paths in the repository (and recursively the
dirnames of those dirnames up until you get to the root).

> So even something simple and stupid like this:

...makes sense.

> restores the v2.42 performance. But there are probably better options:
>
>   - this is caching whole .gitattributes buffers. In pack-objects we
>     only care about a single bit for try_delta. For linux.git it doesn't
>     really matter, as 99% of our entries are just CACHE_MISSING and the
>     real value is avoiding the negative lookups. But the same problem
>     exists to a lesser degree for "git log -p" in a bare repo. So I
>     think it makes sense to try to solve it in the attr layer.
>
>   - the string keys have a lot of duplication. You'll have
>     "foo/.gitattributes", "foo/bar/.gitattributes", and so on. A trie
>     structure split by path component would let you store each component
>     just once. And perhaps have even faster lookups. I think this is
>     roughly the same issue faced by the kernel VFS for doing path
>     lookups, so something dentry/dcache-like would help.
>
>     I don't know how much it matters in practice, though. The sum of all
>     of the paths in HEAD for linux.git is ~3.5MB, which is a rounding
>     error on the needs of the rest of the packing process.

This was my gut reaction when I started reading this bullet point, too.
I have a hard time imagining a repository that would be so large that it
would have a lot of unique paths, but not so large that it would be
otherwise cheap to run pack-objects.

>   - As noted above, most entries are just CACHE_MISSING. So rather than
>     lazily looking up and caching entries, we could just prepopulate the
>     cache. And then you know that if an entry isn't present in the
>     cache, it does not exist in the tree. The downside is that you pay
>     to walk the all of HEAD^{tree}, even if you only have a few lookups
>     to do. That's a good tradeoff for pack-objects (which usually ends
>     up looking for every path anyway), but not for "git diff" (where you
>     only care about a few changed paths.

That seems reasonable to do.

Thanks,
Taylor


  parent reply	other threads:[~2024-05-02  0:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01  5:26 Help troubleshoot performance regression cloning with depth: git 2.44 vs git 2.42 Dhruva Krishnamurthy
2024-05-01 22:00 ` using tree as attribute source is slow, was " Jeff King
2024-05-01 22:37   ` rsbecker
2024-05-01 22:40   ` Junio C Hamano
2024-05-02  0:33   ` Taylor Blau [this message]
2024-05-02 17:33     ` Taylor Blau
2024-05-02 17:44       ` Junio C Hamano
2024-05-02 17:55         ` Taylor Blau
2024-05-02 19:01           ` Karthik Nayak
2024-05-02 21:08             ` Junio C Hamano
2024-05-03  5:37               ` Dhruva Krishnamurthy
2024-05-03 15:34                 ` Re* " Junio C Hamano
2024-05-03 17:46                   ` Jeff King
2024-05-06 20:28                     ` Taylor Blau
2024-05-13 20:16                   ` John Cai
2024-05-02 18:34         ` Dhruva Krishnamurthy
2024-05-02  0:45   ` Dhruva Krishnamurthy

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZjLfcCxjLq4o7hpw@nand.local \
    --to=me@ttaylorr.com \
    --cc=dhruvakm@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johncai86@gmail.com \
    --cc=karthik.188@gmail.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).