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

git grep with leading inverted bracket expression

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

Next: Ævar Arnfjörð Bjarmason
Message 1 of 4 in “git grep with leading inverted bracket expression”
  1. Matthew WilcoxJun 7, 2018
  2. Ævar Arnfjörð BjarmasonJun 7, 2018
  3. Matthew WilcoxJun 7, 2018
  4. Ævar Arnfjörð BjarmasonJun 7, 2018

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.