3 ms·
Why is this? Would anyone with a better understanding of the situation care to explain why it would be faster?
by iambot 13y ago
Why is this? Would anyone with a better understanding of the situation care to explain why it would be faster?
- bbrks 13y agoI'm not quite, sure. But here's why GNU grep is fast [1] 1. http://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html http://lists.freebsd.org/pipermail/freebsd-current/2010-Augu...
- dfc 13y agoSee my comment[1], your intuition was correct. [1] https://news.ycombinator.com/item?id=6016352 https://news.ycombinator.com/item?id=6016352
- asianexpress 13y agoNot 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 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?).
- raylu 13y agoIf 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.
- reddit_clone 13y agoIf I were to guess, I would think grep has to traverse the directory tree while git knows all the file names already.
- abc_lisper 13y agoThis 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.
- nilved 13y agoDoesn't git already have a compressed and optimized index of your files?
- cjp 13y agoIn 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.
- vdm 13y agoAfter config/parsing, it runs the search at the end of cmd_grep in https://github.com/git/git/blob/master/builtin/grep.c?source=c 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.