git grep with leading inverted bracket expression
- From
- Matthew Wilcox <willy@infradead.org>
- Date
- Jun 7, 2018, 15:27 UTC
- Message-ID
- <20180607152711.GA27079@bombadil.infradead.org>
If the first atom of a regex is a bracket expression with an inverted range, git grep is very slow.
$ time git grep 'struct_size' >/dev/null
real 0m0.368s user 0m0.563s sys 0m0.453s
$ time git grep '[^t]truct_size' >/dev/null
real 0m31.529s user 1m54.909s sys 0m0.805s
If the bracket expression is moved to even the second position in the string, it runs much faster:
$ time git grep 's[^p]ruct_size' >/dev/null
real 0m3.989s user 0m13.939s sys 0m0.403s
It's pretty bad with even a '.' as the first character:
$ time git grep '.truct_size' >/dev/null
real 0m14.514s user 0m52.624s sys 0m0.598s
$ git --version git version 2.17.1
Setting LANG=C improves matters by a factor of 3-4 (depending if you count real or user time):
$ time git grep '[^t]truct_size' >/dev/null real 0m10.035s user 0m28.795s sys 0m0.537s
(this is using something pretty close to Linus' current HEAD of the linux repository, an i7-7500, 16GB memory).