Skip to contentSkip to conversation

Add git-grep threads param

PATCH Superseded Victor Leschuk 2 participants 2 messages Jun 15, 2016 Documentation

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 Add git-grep threads param

"git grep" can now be configured (or told from the command line)
how many threads to use when searching in the working tree files.

---
 Documentation/config.txt               |  7 +++++
 Documentation/git-grep.txt             | 15 ++++++++++
 builtin/grep.c                         | 50 +++++++++++++++++++++++-----------
 contrib/completion/git-completion.bash |  1 +
 4 files changed, 57 insertions(+), 16 deletions(-)
Documentation/config.txt +7 -0
index 391a0c3..467fa7b 100644
@@ -1447,6 +1447,13 @@ grep.extendedRegexp::
 	option is ignored when the 'grep.patternType' option is set to a value
 	other than 'default'.
 
+grep.threads::
+	Number of grep worker threads, use it to tune up performance on
+	your machines. Leave it unset (or set to 0) for default behavior,
+	which for now is using 8 threads for all systems.
+	Default behavior can be changed in future versions
+	to better suite hardware and circumstances.
+
 gpg.program::
 	Use this custom program instead of "gpg" found on $PATH when
 	making or verifying a PGP signature. The program must support the
Documentation/git-grep.txt +15 -0
index 4a44d6d..91027b6 100644
@@ -23,6 +23,7 @@ SYNOPSIS
 	   [--break] [--heading] [-p | --show-function]
 	   [-A <post-context>] [-B <pre-context>] [-C <context>]
 	   [-W | --function-context]
+	   [--threads <num>]
 	   [-f <file>] [-e] <pattern>
 	   [--and|--or|--not|(|)|-e <pattern>...]
 	   [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
@@ -53,6 +54,13 @@ grep.extendedRegexp::
 	option is ignored when the 'grep.patternType' option is set to a value
 	other than 'default'.
 
+grep.threads::
+	Number of grep worker threads, use it to tune up performance on
+	your machines. Leave it unset (or set to 0) for default behavior,
+	which for now is using 8 threads for all systems.
+	Default behavior can be changed in future versions
+	to better suite hardware and circumstances.
+
 grep.fullName::
 	If set to true, enable '--full-name' option by default.
 
@@ -227,6 +235,13 @@ OPTIONS
 	effectively showing the whole function in which the match was
 	found.
 
+--threads <num>::
+	Number of grep worker threads, use it to tune up performance on
+	your machines. Leave it unset (or set to 0) for default behavior,
+	which for now is using 8 threads for all systems.
+	Default behavior can be changed in future versions
+	to better suite hardware and circumstances.
+
 -f <file>::
 	Read patterns from <file>, one per line.
 
builtin/grep.c +34 -16

135 lines not on this page · raw message

contrib/completion/git-completion.bash +1 -0
index 482ca84..390d9c0 100644
@@ -1310,6 +1310,7 @@ _git_grep ()
 			--full-name --line-number
 			--extended-regexp --basic-regexp --fixed-strings
 			--perl-regexp
+			--threads
 			--files-with-matches --name-only
 			--files-without-match
 			--max-depth
Signature · 1 line
2.6.3.369.g3e7f205.dirty
#1 lore raw
Quoted 5 lines · Victor Leschuk

"git grep" can now be configured (or told from the command line)
how many threads to use when searching in the working tree files.

---

As an aid for reviewers, please use this space (below the "---" line) to describe what changed since the previous version. It's also helpful if you can provide a link to the previous version in the mailing list archive.

Quoted 8 lines
 Documentation/config.txt               |  7 +++++
 Documentation/git-grep.txt             | 15 ++++++++++
 builtin/grep.c                         | 50 +++++++++++++++++++++++-----------
 contrib/completion/git-completion.bash |  1 +
 4 files changed, 57 insertions(+), 16 deletions(-)

Documentation/config.txt grep.extendedRegexp:: · line 1455

Quoted 9 lines
Documentation/config.txt +6 -0
@@ -1447,6 +1447,13 @@ grep.extendedRegexp::
        option is ignored when the 'grep.patternType' option is set to a value
        other than 'default'.
 
+grep.threads::
+       Number of grep worker threads, use it to tune up performance on
+       your machines. Leave it unset (or set to 0) for default behavior,
+       which for now is using 8 threads for all systems.
+       Default behavior can be changed in future versions
+       to better suite hardware and circumstances.

s/suite/suit/ (here and elsewhere)

Was the conclusion of discussion that there should be some explanation here that this is more about tuning for I/O rather than CPU, or did I misunderstand?

Quoted 10 lines
Documentation/config.txt +0 -0
 gpg.program::
        Use this custom program instead of "gpg" found on $PATH when
        making or verifying a PGP signature. The program must support the
Documentation/git-grep.txt +0 -0
index 4a44d6d..91027b6 100644
builtin/grep.c +0 -0
@@ -832,14 +846,18 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        }

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 854

Quoted 10 lines
builtin/grep.c +6 -2
 
 #ifndef NO_PTHREADS
-       if (list.nr || cached || online_cpus() == 1)
-               use_threads = 0;
+       if (list.nr || cached)
+               num_threads = 0; /* Can not multi-thread object lookup */
+       else if (num_threads == 0)
+               num_threads = GREP_NUM_THREADS_DEFAULT; /* User didn't specify value, or just wants default behavior */
+       else if (num_threads < 0)
+               die("Invalid number of threads specified (%d)", num_threads);

The original code consulted online_cpus(), but the new code does not. This is a sufficiently significant change that it deserves mention in the commit message. In fact, it's really a distinct change which might deserve being done in its own preparatory patch (with an explanation something along the lines of "even single-core machines may benefit from threading when the bottleneck is I/O").

Quoted 4 lines
builtin/grep.c +1 -1
 #else
-       use_threads = 0;
+       num_threads = 0;
 #endif