All of lore.kernel.org
 help / color / mirror / Atom feed
* git grep with leading inverted bracket expression
@ 2018-06-07 15:27 Matthew Wilcox
  2018-06-07 19:09 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2018-06-07 15:27 UTC (permalink / raw)
  To: git


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).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-07 19:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 15:27 git grep with leading inverted bracket expression Matthew Wilcox
2018-06-07 19:09 ` Ævar Arnfjörð Bjarmason
2018-06-07 19:22   ` Matthew Wilcox
2018-06-07 19:29     ` Ævar Arnfjörð Bjarmason

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.