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

Re: three-way diff performance problem

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 21, 2009, 19:31 UTC
Message-ID
<alpine.LFD.2.01.0907211225220.19335@localhost.localdomain>
In-Reply-To
<7v7hy1g7vg.fsf@alter.siamese.dyndns.org>
On Tue, 21 Jul 2009, Junio C Hamano wrote:
> 
> What's that cmovne?
It's "conditional move if not equal".
So the source code is
                /* We cannot squash it with earlier one */
                for (lline = sline->lost_head;
                     lline;
                     lline = lline->next)
                        if (lline->parent_map & this_mask)
                                last_one = lline;
adn the compiler has generated this:
	loop:
		test   %r14,0x10(%rdx)
		cmovne %rdx,%rcx
		mov    (%rdx),%rdx
		test   %rdx,%rdx
		jne loop

from it. In the above, '%r14' contains this_mask, and '%rcx' contains 'last_line' and '%rdx' contains 'lline'.

So:
 - test   %r14,0x10(%rdx)
   test "this_mask & lline->parent_map"
 - cmovne %rdx,%rcx
   "if the test above was non-zero, then last_one = lline"
 - mov    (%rdx),%rdx
   "lline = lline->next"
 - test   %rdx,%rdx
   "is lline NULL"
 - jne loop
   no, continue.
Show 12 quoted lines
> The function append_lost() is the meat of combining.  When you have seen
> a hunk like this:
> 
>     @@ -l,k +m,n @@
>     -lost line
>     -another lost line
>      common line
>     +added line
> 
> We queue the lost lines in front of a surviving line (that is sline that
> points at "common line").  "lost line" and "another lost line" are stored
> in lline (lost line) and they are queued to sline->lost_head.
Right. And "sline->lost_head" is going to have over a _million_ entries.

So each time you add one, we'll traverse that loop a million times. For each new entry. End result: that loop gets executed on the order of a million million times. It doesn't help that the compiler made it be very efficient code ;(

			Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 8 in “three-way diff performance problem”
  1. Linus TorvaldsJul 21, 2009
  2. Linus TorvaldsJul 21, 2009
  3. Junio C HamanoJul 21, 2009
  4. Linus TorvaldsJul 21, 2009
  5. Junio C HamanoJul 21, 2009
  6. Linus TorvaldsJul 21, 2009
  7. Junio C HamanoJul 21, 2009
  8. Linus TorvaldsJul 21, 2009

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.