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

Re: [RFC PATCH] Fix quadratic performance in rewrite_one.

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Jul 13, 2008, 00:37 UTC
Message-ID
<200807130437.59141.angavrilov@gmail.com>
In-Reply-To
<alpine.LFD.1.10.0807121550320.2959@woody.linux-foundation.org>
On Sunday 13 July 2008 02:55:27 Linus Torvalds wrote:
Show 8 quoted lines
> On Sat, 12 Jul 2008, Alexander N. Gavrilov wrote:
> > Parent commits are usually older than their children. Thus,
> > on each iteration of the loop in rewrite_one, add_parents_to_list
> > traverses all commits previously processed by the loop.
> > It performs very poorly in case of very long rewrite chains.
>
> Good call, but you don't seem to invalidate the cache when we remove
> things from the list.

The cache is local to rewrite_one, and is invalidated by exiting from that function. Other users of add_parents_to_list just pass NULL as cache_ptr, thus causing insert_by_date_cached to degenerate into a simple insert_by_date.

> The top of the limit_list() loop does that "get top entry from list, an
> free it", and I'm not seeing you invalidating the cache if that entry that
> just got free'd happened to be the cache entry?

This type of workflow can be expected to keep the list relatively short (roughly limited by the number of simultaneously existing branches); and if it is already long, new entries will probably be added near the beginning anyway, so there doesn't seem to be any need to use caching.

rewrite_one() is special in that it can sometimes walk through thousands of commits at once and put them all into the list -- i.e. it is bound not by the width of the history, but by its length.

Alexander
Previous: Linus Torvalds
Message 3 of 3 in “Fix quadratic performance in rewrite_one.”
  1. Fix quadratic performance in rewrite_one.Alexander N. Gavrilov, Jul 12, 2008
  2. Linus TorvaldsJul 12, 2008
  3. Alexander GavrilovJul 13, 2008

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.