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

Re: absurdly slow git-diff

From
DLDavide Libenzi <davidel@xmailserver.org>
Date
Nov 7, 2008, 23:04 UTC
Message-ID
<alpine.DEB.1.10.0811071503120.8736@alien.or.mcafeemobile.com>
In-Reply-To
<alpine.LFD.2.00.0811071335010.3468@nehalem.linux-foundation.org>
On Fri, 7 Nov 2008, Linus Torvalds wrote:
Show 37 quoted lines
> On Sat, 8 Nov 2008, Abhijit Menon-Sen wrote:
> >
> > If anyone's interested, the files are http://toroid.org/misc/1 and
> > http://toroid.org/misc/2
> 
> Btw, you can see this by just doing
> 
> 	git diff 1 2
> 
> without even doing "git init" or doing any actual git repository.
> 
> > Does anyone understand why this slowdown might happen or have
> > suggestions about where I should look for it?
> 
> Sure. It's actually fairly simple. You're hitting a O(n^2) thing (possibly 
> higher), and it's triggered by the fact that almost all your lines are 
> identical, ie you have a file that basically has 40,000 lines of each of
> 
> 	xxxx: xxx, xx xxx xxxx xx:xx:xx +xxxx
> 	xx: xxxx xxxxxxxxxxx <xxxx@xxxx.xxx>
> 	xxxx: xxxx xxxxxxxxxxx <xxxx@xxxx.xxx>
> 
> and 30,000 of 
> 
> 	* xxxxx xxxxx (xxxxxx.xxxx xxx xxxxx (\Xxxxxx) xxxxxx.xxxxxx {xxx}
> 
> with a smattering of others. And this is a case where the internal git 
> implementation does really badly. And nobody has really cared before, 
> because nobody has ever had a case that mattered.
> 
> There's a number of different 'diff' algorithms, and it looks like GNU 
> diff has one that avoids the O(n^2) case for this case.
> 
> I'm adding Davide as the original author of the diff library to the cc. 
> I'm also adding Pierre, since he was talking about trying to implement
> another diff algorithm (although I'm not at all sure that the patience 
> diff really would help this case at all).

That should be an easy fix. Just need to limit the window by which xdl_clean_mmatch() scans the current position.

- Davide
Previous: Linus TorvaldsNext: Davide Libenzi
Message 4 of 13 in “absurdly slow git-diff”
  1. Abhijit Menon-SenNov 7, 2008
  2. Mike HommeyNov 7, 2008
  3. Linus TorvaldsNov 7, 2008
  4. Davide LibenziNov 7, 2008
  5. Davide LibenziNov 7, 2008
  6. Linus TorvaldsNov 7, 2008
  7. Davide LibenziNov 7, 2008
  8. Linus TorvaldsNov 7, 2008
  9. Abhijit Menon-SenNov 8, 2008
  10. Junio C HamanoNov 8, 2008
  11. Junio C HamanoNov 8, 2008
  12. Davide LibenziNov 8, 2008
  13. Pierre HabouzitNov 8, 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.