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

Re: [PATCH] grep: do not do external grep on skip-worktree entries

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 11, 2010, 15:59 UTC
Message-ID
<alpine.LFD.2.00.1001110748560.13040@localhost.localdomain>
In-Reply-To
<alpine.LFD.2.00.1001110739280.13040@localhost.localdomain>
On Mon, 11 Jan 2010, Linus Torvalds wrote:
>
> Without testing it, I can already ACK it. It looks like the 
> ObviouslyRightThing(tm) to do. But I'll run some numbers too.
Ok, some good news, some meh news, and some bad news.

The good news: the trivial numbers look good. It's noticeably faster than external grep for me when it does the 'fixmatch()' case, quite probably because fixmatch() on at least Linux/x86-64 (which is the only case I really care about) uses SSE to do the string ops.

So on my Nehalem:
	[torvalds@nehalem linux]$ time git grep qwerty > /dev/null 
	real	0m0.418s
	user	0m0.204s
	sys	0m0.136s
	[torvalds@nehalem linux]$ time git grep --no-ext-grep qwerty > /dev/null 
	real	0m0.309s
	user	0m0.168s
	sys	0m0.136s
and since that simple fixmatch case is the common one for me, I'm happy.

The meh news: this shows how grep is faster than regexec() due to being a smarter algorithm. For the non-fixed case (I used "qwerty.*as"), the numbers are

 - built-in:
	real	0m0.548s
	user	0m0.384s
	sys	0m0.152s
 - external:
	real	0m0.415s
	user	0m0.176s
	sys	0m0.160s

so it really is just 'strstr()' that is faster. But This is a 'meh', because I don't really care, and the new code is still way faster than the old one. And I'd be personally willing to just drop the external grep if this is the worst problem.

[ I worry a bit that some libc implementations of 'strstr' may suck, but I 
  wouldn't lose sleep over it. ]
The bad news is that you broke multi-line greps:
	git grep --no-ext-grep -2 qwerty.*as
results in:
	drivers/char/keyboard.c-unsigned char kbd_sysrq_xlate[KEY_MAX + 1] =
	drivers/char/keyboard.c-        "\000\0331234567890-=\177\t"                    /* 0x00 - 0x0f */
	drivers/char/keyboard.c:        "qwertyuiop[]\r\000as"                          /* 0x10 - 0x1f */
when the _correct_ result is 
	drivers/char/keyboard.c-unsigned char kbd_sysrq_xlate[KEY_MAX + 1] =
	drivers/char/keyboard.c-        "\000\0331234567890-=\177\t"                    /* 0x00 - 0x0f */
	drivers/char/keyboard.c:        "qwertyuiop[]\r\000as"                          /* 0x10 - 0x1f */
	drivers/char/keyboard.c-        "dfghjkl;'`\000\\zxcv"                          /* 0x20 - 0x2f */
	drivers/char/keyboard.c-        "bnm,./\000*\000 \000\201\202\203\204\205"      /* 0x30 - 0x3f */
ie it didn't do the "two lines after" thing.

That said, the external grep also gets this wrong (a different way), because it gets all the extra noise due to unnecessary separation lines, so for the external grep I actually get

	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	drivers/char/keyboard.c-unsigned char kbd_sysrq_xlate[KEY_MAX + 1] =
	drivers/char/keyboard.c-        "\000\0331234567890-=\177\t"                    /* 0x00 - 0x0f */
	drivers/char/keyboard.c:        "qwertyuiop[]\r\000as"                          /* 0x10 - 0x1f */
	drivers/char/keyboard.c-        "dfghjkl;'`\000\\zxcv"                          /* 0x20 - 0x2f */
	drivers/char/keyboard.c-        "bnm,./\000*\000 \000\201\202\203\204\205"      /* 0x30 - 0x3f */
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--
	--

but that's a long-standing problem, and is more "ugly" than "wrong grep results".

			Linus
Previous: Linus TorvaldsNext: Junio C Hamano
Message 27 of 60 in “grep: do not do external grep on skip-worktree entries”
  1. grep: do not do external grep on skip-worktree entriesNguyễn Thái Ngọc Duy, Dec 30, 2009
  2. Junio C HamanoDec 31, 2009
  3. Junio C HamanoDec 31, 2009
  4. Nguyen Thai Ngoc DuyJan 2, 2010
  5. Junio C HamanoJan 2, 2010
  6. Nguyen Thai Ngoc DuyJan 2, 2010
  7. Junio C HamanoJan 2, 2010
  8. Miles BaderJan 3, 2010
  9. Miles BaderJan 3, 2010
  10. Miles BaderJan 3, 2010
  11. Linus TorvaldsJan 3, 2010
  12. Junio C HamanoJan 3, 2010
  13. Jeff KingJan 4, 2010
  14. Junio C HamanoJan 4, 2010
  15. Jeff KingJan 4, 2010
  16. Junio C HamanoJan 4, 2010
  17. Junio C HamanoJan 4, 2010
  18. Jeff KingJan 4, 2010
  19. Jeff KingJan 4, 2010
  20. Jeff KingJan 4, 2010
  21. Linus TorvaldsJan 4, 2010
  22. Linus TorvaldsJan 4, 2010
  23. Miles BaderJan 4, 2010
  24. Linus TorvaldsJan 4, 2010
  25. Junio C HamanoJan 11, 2010
  26. Linus TorvaldsJan 11, 2010
  27. Linus TorvaldsJan 11, 2010
  28. Junio C HamanoJan 11, 2010
  29. Junio C HamanoJan 11, 2010
  30. Linus TorvaldsJan 11, 2010
  31. Junio C HamanoJan 12, 2010
  32. grep: lookahead optimization can be used with -L optionJunio C Hamano, Jan 12, 2010
  33. grep: -L should show empty filesJunio C Hamano, Jan 12, 2010
  34. Sverre RabbelierJan 12, 2010
  35. Junio C HamanoJan 13, 2010
  36. Sverre RabbelierJan 13, 2010
  37. Junio C HamanoJan 13, 2010
  38. 1/2 grep: rip out support for external grepJunio C Hamano, Jan 13, 2010
  39. Jay SoffianJan 13, 2010
  40. Junio C HamanoJan 13, 2010
  41. Linus TorvaldsJan 13, 2010
  42. 2/2 grep: rip out pessimization to use fixmatch()Junio C Hamano, Jan 13, 2010
  43. Jeff KingJan 12, 2010
  44. Fredrik KuivinenJan 11, 2010
  45. Linus TorvaldsJan 4, 2010
  46. Nguyen Thai Ngoc DuyJan 4, 2010
  47. Mike HommeyJan 4, 2010
  48. Jeff KingJan 4, 2010
  49. 1/2 t7002: set test prerequisite "external-grep" if supportedNguyễn Thái Ngọc Duy, Jan 4, 2010
  50. Junio C HamanoJan 7, 2010
  51. Junio C HamanoJan 7, 2010
  52. Nguyen Thai Ngoc DuyJan 7, 2010
  53. Johannes SixtJan 7, 2010
  54. Nguyen Thai Ngoc DuyJan 7, 2010
  55. 2/2 t7002: add tests for skip-worktree fixes in commit a67e281Nguyễn Thái Ngọc Duy, Jan 4, 2010
  56. Linus TorvaldsJan 11, 2010
  57. Fredrik KuivinenJan 11, 2010
  58. Linus TorvaldsJan 11, 2010
  59. Fredrik KuivinenJan 11, 2010
  60. Linus TorvaldsJan 11, 2010

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.