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

Re: git diff: support "-U" and "--unified" options properly

From
Linus Torvalds <torvalds@osdl.org>
Date
May 13, 2006, 22:39 UTC
Message-ID
<Pine.LNX.4.64.0605131518390.3866@g5.osdl.org>
In-Reply-To
<7vpsihsjq6.fsf@assigned-by-dhcp.cox.net>
On Sat, 13 May 2006, Junio C Hamano wrote:
> 
>  * built-in grep (jc/grep)
> 
>    Ready.
I'm not entirely convinced.
For the kernel, I currently can do a 
	git grep some-random-string
in about half a second.
The new built-in grep is about ten times slower.
Before:
   [torvalds@g5 linux]$ /usr/bin/time git grep some-random-string
   Command exited with non-zero status 123
   0.29user 0.30system 0:00.52elapsed 113%CPU (0avgtext+0avgdata 0maxresident)k
   0inputs+0outputs (0major+3206minor)pagefaults 0swaps
After:
   [torvalds@g5 linux]$ /usr/bin/time git grep some-random-string
   Command exited with non-zero status 1
   4.60user 0.33system 0:04.98elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
   0inputs+0outputs (0major+7369minor)pagefaults 0swaps

and that "half a second" vs "five seconds" difference is really noticeable.

Right now I do "git grep" as a random "ok, where was it", and it works very well, because it's basically instantaneous. And the difference between "instantaneous" and "5 seconds" is very big (the five seconds is also long enough that the CPU fan comes on on my G5, which is my sign of "too much work for the CPU".

I haven't looked at _why_ the builtin grep is ten times slower. I suspect it's just the regexp library being a lot slower than the external optimized grep, but it may also be just overhead (it looks, for example, like the builtin grep does all matches just one line at a time. And it actually reads the file in, when mmap might be more efficient, I dunno).

Regardless, it's a huge downer.
		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 21 in “git diff: support "-U" and "--unified" options properly”
  1. Linus TorvaldsMay 13, 2006
  2. Junio C HamanoMay 13, 2006
  3. Junio C HamanoMay 13, 2006
  4. Linus TorvaldsMay 13, 2006
  5. Junio C HamanoMay 13, 2006
  6. Linus TorvaldsMay 13, 2006
  7. Junio C HamanoMay 15, 2006
  8. Linus TorvaldsMay 15, 2006
  9. Junio C HamanoMay 15, 2006
  10. Linus TorvaldsMay 15, 2006
  11. Martin LanghoffMay 14, 2006
  12. Josef WeidendorferMay 14, 2006
  13. Junio C HamanoMay 14, 2006
  14. Branch relationships (was:Re: git diff: support "-U" and "--unified" options properly)Josef Weidendorfer, May 14, 2006
  15. Junio C HamanoMay 14, 2006
  16. Josef WeidendorferMay 14, 2006
  17. Junio C HamanoMay 14, 2006
  18. Josef WeidendorferMay 14, 2006
  19. Junio C HamanoMay 14, 2006
  20. Josef WeidendorferMay 15, 2006
  21. Junio C HamanoMay 15, 2006

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.