Skip to content

Commit 1184a95

Browse files
matheustavaresgitster
authored andcommitted
grep: re-enable threads in non-worktree case
They were disabled at 53b8d93 ("grep: disable threading in non-worktree case", 12-12-2011), due to observable performance drops (to the point that using a single thread would be faster than multiple threads). But now that zlib inflation can be performed in parallel we can regain the speedup, so let's re-enable threads in non-worktree grep. Grepping 'abcd[02]' ("Regex 1") and '(static|extern) (int|double) \*' ("Regex 2") at chromium's repository[1] I got: Threads | Regex 1 | Regex 2 ---------|------------|----------- 1 | 17.2920s | 20.9624s 2 | 9.6512s | 11.3184s 4 | 6.7723s | 7.6268s 8** | 6.2886s | 6.9843s These are all means of 30 executions after 2 warmup runs. All tests were executed on an i7-7700HQ (quad-core w/ hyper-threading), 16GB of RAM and SSD, running Manjaro Linux. But to make sure the optimization also performs well on HDD, the tests were repeated on another machine with an i5-4210U (dual-core w/ hyper-threading), 8GB of RAM and HDD (SATA III, 5400 rpm), also running Manjaro Linux: Threads | Regex 1 | Regex 2 ---------|------------|----------- 1 | 18.4035s | 22.5368s 2 | 12.5063s | 14.6409s 4** | 10.9136s | 12.7106s ** Note that in these cases we relied on hyper-threading, and that's probably why we don't see a big difference in time. Unfortunately, multithreaded git-grep might be slow in the non-worktree case when --textconv is used and there're too many text conversions. Probably the reason for this is that the object read lock is used to protect fill_textconv() and therefore there is a mutual exclusion between textconv execution and object reading. Because both are time-consuming operations, not being able to perform them in parallel can cause performance drops. To inform the users about this (and other threading details), let's also add a "NOTES ON THREADS" section to Documentation/git-grep.txt. [1]: chromium’s repo at commit 03ae96f (“Add filters testing at DSF=2”, 04-06-2019), after a 'git gc' execution. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c30762 commit 1184a95

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Documentation/git-grep.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ EXAMPLES
347347
`git grep solution -- :^Documentation`::
348348
Looks for `solution`, excluding files in `Documentation`.
349349

350+
NOTES ON THREADS
351+
----------------
352+
353+
The `--threads` option (and the grep.threads configuration) will be ignored when
354+
`--open-files-in-pager` is used, forcing a single-threaded execution.
355+
356+
When grepping the object store (with `--cached` or giving tree objects), running
357+
with multiple threads might perform slower than single threaded if `--textconv`
358+
is given and there're too many text conversions. So if you experience low
359+
performance in this case, it might be desirable to use `--threads=1`.
360+
350361
GIT
351362
---
352363
Part of the linkgit:git[1] suite

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10541054
if (recurse_submodules && (!use_index || untracked))
10551055
die(_("option not supported with --recurse-submodules"));
10561056

1057-
if (list.nr || cached || show_in_pager) {
1057+
if (show_in_pager) {
10581058
if (num_threads > 1)
10591059
warning(_("invalid option combination, ignoring --threads"));
10601060
num_threads = 1;

0 commit comments

Comments
 (0)