From: Matthew Wilcox <willy@infradead.org>
To: git@vger.kernel.org
Subject: git grep with leading inverted bracket expression
Date: Thu, 7 Jun 2018 08:27:11 -0700 [thread overview]
Message-ID: <20180607152711.GA27079@bombadil.infradead.org> (raw)
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 reply other threads:[~2018-06-07 15:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-07 15:27 Matthew Wilcox [this message]
2018-06-07 19:09 ` git grep with leading inverted bracket expression Ævar Arnfjörð Bjarmason
2018-06-07 19:22 ` Matthew Wilcox
2018-06-07 19:29 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180607152711.GA27079@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).