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

Re: [PATCH v2] Add git-grep threads-num param

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 23, 2015, 22:40 UTC
Message-ID
<xmqqbnbpnr7u.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1445591717-5998-1-git-send-email-vleschuk@accesssoftek.com>

Please pay attention to your title. It no longer matches what the patch does.

It may also be beneficial to study recent titles and log messages from other developers (you can find them in "git log --no-merges" and "git shortlog --no-merges") and learn and imitate their format, style and tone. We want our log to tell a story in a consistent voice, no matter who the authors of individual commits are.

Victor Leschuk <vleschuk@gmail.com> writes:
> It's a follow up to "[PATCH] Add git-grep threads-num param":

Do you think anybody wants to see this line in the output from "git log" six months from now? I doubt it. The previous one will not be committed to my tree anyway, so the readers would not know (nor care) what other patch you are talking about.

Show 7 quoted lines
> @@ -832,7 +836,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  	}
>  
>  #ifndef NO_PTHREADS
> -	if (list.nr || cached || online_cpus() == 1)
> +	if (list.nr || cached || online_cpus() == 1 || opt.num_threads <= 1)
>  		use_threads = 0;

This avoid --threads=0 to take the threading codepath and spawning no threads, which would have happend in the previous patch.

But it makes me wonder if the logic should be more like this:
    
 - Because the code is not prepared to go multi-thread when
   searching in the object data (not working tree), we always
   disable threading if 'list' is not empty or 'cached' is given;
   otherwise
 - If the user explicitly said that she wants N threads, we use that
   many threads; otherwise
 - If there is only one CPU, we do not do multi-thread; otherwise
 - We use the default number of threads.

IOW, I'd suggest making opt.num_threads an "int" (not "unsigned"), initialize it to -1 (unspecified), and then make this part more like this, perhaps?

	if (!opt.num_threads)
        	use_threads = 0; /* the user tells us not to use threads */
	else if (list.nr || cached)
        	use_threads = 0; /* cannot multi-thread object lookup */
	else if (opt.num_threads >= 1)
		use_threads = 1; /* the user explicitly wants this many */
	else if (online_cpus() <= 1)
        	use_threads = 0;
	else {
        	use_threads = 1;
                opt.num_threads = GREP_NUM_THREADS_DEFAULT;
	}

Something like this code structure makes it very clear what needs to be changed when we want to add some sort of auto-scaling (instead of assigning the DEFAULT constant, you'd see how many cores you have, how many files you will be grepping in, etc. and come up with a good number dynamically).

Show 5 quoted lines
> @@ -150,6 +159,8 @@ void grep_init(struct grep_opt *opt, const char *prefix)
>  	opt->pathname = def->pathname;
>  	opt->regflags = def->regflags;
>  	opt->relative = def->relative;
> +	if(!opt->num_threads)

You forgot a required SP between a keyword for a syntactic construct and its open parenthesis.

Thanks.
Previous: Victor Leschuk
Message 2 of 2 in “Add git-grep threads-num param”
  1. Add git-grep threads-num paramVictor Leschuk, Oct 23, 2015
  2. Junio C HamanoOct 23, 2015

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.