Skip to content

Commit 70a9fef

Browse files
matheustavaresgitster
authored andcommitted
grep: move driver pre-load out of critical section
In builtin/grep.c:add_work() we pre-load the userdiff drivers before adding the grep_source in the todo list. This operation is currently being performed after acquiring the grep_mutex, but as it's already thread-safe, we don't need to protect it here. So let's move it out of the critical section which should avoid thread contention and improve performance. Running[1] `git grep --threads=8 abcd[02] HEAD` on chromium's repository[2], I got the following mean times for 30 executions after 2 warmups: Original | 6.2886s -------------------------|----------- Out of critical section | 5.7852s [1]: Tests performed on an i7-7700HQ with 16GB of RAM and SSD, running Manjaro Linux. [2]: 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 1184a95 commit 70a9fef

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/grep.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ static pthread_cond_t cond_result;
9292

9393
static int skip_first_line;
9494

95-
static void add_work(struct grep_opt *opt, const struct grep_source *gs)
95+
static void add_work(struct grep_opt *opt, struct grep_source *gs)
9696
{
97+
if (opt->binary != GREP_BINARY_TEXT)
98+
grep_source_load_driver(gs, opt->repo->index);
99+
97100
grep_lock();
98101

99102
while ((todo_end+1) % ARRAY_SIZE(todo) == todo_done) {
100103
pthread_cond_wait(&cond_write, &grep_mutex);
101104
}
102105

103106
todo[todo_end].source = *gs;
104-
if (opt->binary != GREP_BINARY_TEXT)
105-
grep_source_load_driver(&todo[todo_end].source,
106-
opt->repo->index);
107107
todo[todo_end].done = 0;
108108
strbuf_reset(&todo[todo_end].out);
109109
todo_end = (todo_end + 1) % ARRAY_SIZE(todo);

0 commit comments

Comments
 (0)