Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Henrique Ferreiro via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Henrique Ferreiro <hferreiro@igalia.com>
Subject: Re: [PATCH v2] unpack-trees: avoid quadratic index scan in next_cache_entry()
Date: Wed, 08 Jul 2026 14:58:04 -0700	[thread overview]
Message-ID: <xmqqpl0xqh3n.fsf@gitster.g> (raw)
In-Reply-To: <pull.2353.v2.git.git.1783546933992.gitgitgadget@gmail.com> (Henrique Ferreiro via GitGitGadget's message of "Wed, 08 Jul 2026 21:42:13 +0000")

"Henrique Ferreiro via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Henrique Ferreiro <hferreiro@igalia.com>
>
> Diffing the working tree against a commit with a pathspec can take
> time quadratic in the size of the index when the pathspec matches a
> subtree whose entries are the first entries of the index.  Fix it by
> having next_cache_entry() record how far it scanned in cache_bottom,
> so repeated calls no longer rescan the growing prefix of
> already-unpacked entries.  On a Chromium checkout (~500k index
> entries),
>
> 	git diff HEAD -- .agents/OWNERS
>
> took about 8 minutes before this change and 0.07 seconds after it.
> The same diff without the commit, without the pathspec, or with
> --cached was already instant.
>
> Add p0009-diff-pathspec.sh, which builds a 10,000-entry index whose
> first path lives in a subtree (100,000 entries under --long-tests),
> to guard against the regression.  Comparing v2.55.0 with this change
> using GIT_TEST_LONG=t:
>
> Test                            v2.55.0           HEAD
> ------------------------------------------------------------------------
> 0009.2: diff pathspec subtree   7.16(7.12+0.01)   0.02(0.01+0.00) -99.7%
>
> Signed-off-by: Henrique Ferreiro <hferreiro@igalia.com>
> ---
>     unpack-trees: avoid quadratic index scan in next_cache_entry()
>     
>     Changes since v1: adjust the synthetic index size based on the EXPENSIVE
>     prerequisite.

Thanks.

      reply	other threads:[~2026-07-08 21:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 21:01 [PATCH] unpack-trees: avoid quadratic index scan in next_cache_entry() Henrique Ferreiro via GitGitGadget
2026-07-07 21:30 ` Junio C Hamano
2026-07-08 18:31   ` Henrique Ferreiro
2026-07-08 19:16     ` Junio C Hamano
2026-07-08 21:40       ` Henrique Ferreiro
2026-07-08 21:42 ` [PATCH v2] " Henrique Ferreiro via GitGitGadget
2026-07-08 21:58   ` Junio C Hamano [this message]

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=xmqqpl0xqh3n.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=hferreiro@igalia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox