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

Re: [PATCH v2] unpack-trees: avoid quadratic index scan in next_cache_entry()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2026, 21:58 UTC
Message-ID
<xmqqpl0xqh3n.fsf@gitster.g>
In-Reply-To
<pull.2353.v2.git.git.1783546933992.gitgitgadget@gmail.com>

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

Show 31 quoted lines
> 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.
Previous: Henrique Ferreiro via GitGitGadget
Message 7 of 7 in “unpack-trees: avoid quadratic index scan in next_cache_entry()”
  1. unpack-trees: avoid quadratic index scan in next_cache_entry()Henrique Ferreiro via GitGitGadget, Jul 7, 2026
  2. Junio C HamanoJul 7, 2026
  3. Henrique FerreiroJul 8, 2026
  4. Junio C HamanoJul 8, 2026
  5. Henrique FerreiroJul 8, 2026
  6. unpack-trees: avoid quadratic index scan in next_cache_entry()Henrique Ferreiro via GitGitGadget, Jul 8, 2026
  7. Junio C HamanoJul 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.