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

Re: git log filtering

From
Jeff King <peff@peff.net>
Date
Feb 8, 2007, 06:16 UTC
Message-ID
<20070208061654.GA8813@coredump.intra.peff.net>
In-Reply-To
<Pine.LNX.4.64.0702071334060.8424@woody.linux-foundation.org>
On Wed, Feb 07, 2007 at 01:53:18PM -0800, Linus Torvalds wrote:
Show 6 quoted lines
> What's PCRE performance like? I'd hate to make "git grep" slower, and it 
> would be stupid and confusing to use two different regex libraries..
>
> Maybe somebody could test - afaik, PCRE has a regex-compatible (from a API 
> standpoint, not from a regex standpoint!) wrapper thing, and it might be 
> interesting to hear if doing "git grep" is slower or faster..

The patch is delightfully simple (though a real patch would probably be conditional):

diff --git a/Makefile b/Makefile
index aca96c8..cf391dc 100644
--- a/Makefile
+++ b/Makefile
@@ -323,7 +323,7 @@ BUILTIN_OBJS = \
 	builtin-pack-refs.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
-EXTLIBS = -lz
+EXTLIBS = -lz -lpcreposix -lpcre
 
 #
 # Platform specific tweaks
diff --git a/git-compat-util.h b/git-compat-util.h
index c1bcb00..a6c77f9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -40,7 +40,7 @@
 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <assert.h>
-#include <regex.h>
+#include <pcreposix.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>


A few numbers, all from a fully packed kernel repository:

# glibc, trivial regex
$ /usr/bin/time git grep --cached foo >/dev/null
10.07user 0.15system 0:10.23elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+36617minor)pagefaults 0swaps

# glibc, complex regex
$ /usr/bin/time git grep --cached '[a-z][0-9][a-z][0-9][a-z]'  >/dev/null
24.42user 0.15system 0:24.60elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+36210minor)pagefaults 0swaps

# pcre, trivial regex
$ /usr/bin/time git grep --cached foo >/dev/null
7.82user 0.12system 0:08.00elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+36571minor)pagefaults 0swaps

# pcre, complex regex
$ /usr/bin/time git grep --cached '[a-z][0-9][a-z][0-9][a-z]'  >/dev/null
36.51user 0.13system 0:36.65elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+36583minor)pagefaults 0swaps


So the winner seems to vary based on the complexity of the pattern.
There are some less rudimentary but non-git performance tests here:

  http://www.boost.org/libs/regex/doc/gcc-performance.html

In every case there, pcre has either comparable performance, or simply
blows away glibc.

One final note that caused some confusion during my testing: git-grep
still uses external grep for working tree greps (i.e., 'git grep foo').
This meant that 'git grep' and 'git grep --cached' produced wildly
different results once I was using pcre internally. Something to look
out for if we switch to pcre (or any other library which doesn't exactly
match external grep behavior!).

-Peff
Previous: Linus TorvaldsNext: Johannes Schindelin
Message 21 of 34 in “git log filtering”
  1. Don ZickusFeb 7, 2007
  2. Jakub NarebskiFeb 7, 2007
  3. Uwe Kleine-KönigFeb 7, 2007
  4. Johannes SchindelinFeb 7, 2007
  5. Linus TorvaldsFeb 7, 2007
  6. Johannes SchindelinFeb 7, 2007
  7. Linus TorvaldsFeb 7, 2007
  8. Fix "git log -z" behaviourLinus Torvalds, Feb 7, 2007
  9. Junio C HamanoFeb 7, 2007
  10. Don ZickusFeb 7, 2007
  11. Linus TorvaldsFeb 7, 2007
  12. Junio C HamanoFeb 8, 2007
  13. Junio C HamanoFeb 10, 2007
  14. Junio C HamanoFeb 10, 2007
  15. Linus TorvaldsFeb 10, 2007
  16. Don ZickusFeb 7, 2007
  17. Linus TorvaldsFeb 7, 2007
  18. Linus TorvaldsFeb 7, 2007
  19. Junio C HamanoFeb 7, 2007
  20. Linus TorvaldsFeb 7, 2007
  21. Jeff KingFeb 8, 2007
  22. Johannes SchindelinFeb 8, 2007
  23. Jeff KingFeb 8, 2007
  24. Johannes SchindelinFeb 9, 2007
  25. Shawn O. PearceFeb 9, 2007
  26. Johannes SchindelinFeb 9, 2007
  27. Sergey VlasovFeb 9, 2007
  28. Jeff KingFeb 9, 2007
  29. Johannes SchindelinFeb 9, 2007
  30. Jeff KingFeb 9, 2007
  31. Johannes SchindelinFeb 9, 2007
  32. pcre performance, was Re: git log filteringJohannes Schindelin, Mar 7, 2007
  33. Paolo BonziniMar 7, 2007
  34. Horst H. von BrandFeb 8, 2007

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.