Re:Grep too slow? Use git-grep
by iambot on Tuesday July 09, 2013 @05:38PM
(#6015725)
Why is this? Would anyone with a better understanding of the situation care to explain why it would be faster?
[ Parent
| on HN ]
I'm not quite, sure. But here's why GNU grep is fast [1]
1. http://lists.freebsd.org/pipermail/freebsd-current/2010-Augu...
See my comment[1], your intuition was correct.
In a packed repo, git grep can mmap the pack file once and search through it in one fell swoop. If the pack file isn't already in the filesystem buffer, mmap will get it there quickly. The number of system calls is O(1).
The limitation, as others have said, is git grep won't match files that are not already checked in.
In a regular directory tree, recursive grep has to open and read directories, stat files, and read (or mmap?) each individual file. The number of system calls is O(N) on the number of directory entries.
Re:Grep too slow? Use git-grep
by asianexpress on Tuesday July 09, 2013 @05:50PM
(#6015810)
Not sure if this is the primary reason, but:
"Look for specified patterns in the tracked files in the work tree"
http://git-scm.com/docs/git-grep
Presumably, this would exclude a lot of assets or libraries that aren't part of your branch/repo, don't know what the OP's setup was (are those 11K+ files all tracked?).
If you have a compiled project, files that aren't tracked include all of your intermediate .o files, for example. If you `grep -r` the wrong way, it may traverse the .git directory.
After config/parsing, it runs the search at the end of cmd_grep in https://github.com/git/git/blob/master/builtin/grep.c?source...
I don't know the answer to your question, but the git source is simple and rewards reading.
Re:Grep too slow? Use git-grep
by reddit_clone on Tuesday July 09, 2013 @05:54PM
(#6015839)
If I were to guess, I would think grep has to traverse the directory tree while git knows all the file names already.
Re:Grep too slow? Use git-grep
by abc_lisper on Tuesday July 09, 2013 @06:10PM
(#6015951)
This I don't believe to be true. For many years, I have kept a file with all the filenames in it, and did a grep on the files in the list, and it is slower than git-grep.