git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Victor Leschuk <vleschuk@gmail.com>
Cc: git@vger.kernel.org, vleschuk@accesssoftek.com,
	john@keeping.me.uk, peff@peff.net, pclouds@gmail.com,
	sunshine@sunshineco.com
Subject: Re: [PATCH 1/2] Introduce grep threads param
Date: Tue, 15 Dec 2015 12:06:16 -0800	[thread overview]
Message-ID: <xmqq60zzfpdz.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: 1450193500-22468-2-git-send-email-vleschuk@accesssoftek.com

Victor Leschuk <vleschuk@gmail.com> writes:

> Subject: Re: [PATCH 1/2] Introduce grep threads param

I'll retitle this to something like

    grep: add --threads=<num> option and grep.threads configuration

while queuing (which I did for v7 earlier).

>  "git grep" can now be configured (or told from the command line)
>  how many threads to use when searching in the working tree files.
>
> Signed-off-by: Victor Leschuk <vleschuk@accesssoftek.com>
> ---
> ...
> +grep.threads::
> +	Number of grep worker threads.

"Number of grep worker threads to use"?

> +	See `grep.threads` in linkgit:git-grep[1] for more information.
> ...
> +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 is using 8 threads for all systems.
> +	Default behavior may change in future versions
> +	to better suit hardware and circumstances.

The last sentence is too noisy.  Perhaps drop it and phrase it like
this instead?

    grep.threads::
            Number of grep worker threads to use.  If unset (or set to 0),
            to 0), 8 threads are used by default (for now).

> diff --git a/builtin/grep.c b/builtin/grep.c
> index 4229cae..e9aebab 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -24,11 +24,11 @@ static char const * const grep_usage[] = {
>  	NULL
>  };
>  
> -static int use_threads = 1;
> +#define GREP_NUM_THREADS_DEFAULT 8
> +static int num_threads = 0;

Please do not initialize static to 0 (or NULL).

> @@ -267,6 +270,12 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
>  	int st = grep_config(var, value, cb);
>  	if (git_color_default_config(var, value, cb) < 0)
>  		st = -1;
> +
> +	if (!strcmp(var, "grep.threads")) {
> +		/* Sanity check of value will be perfomed later */

Hmm, is that a good design?

A user may hear "invalid number of threads specified (-4)" later,
but if that came from "grep.threads", especially when the user did
not say "--threads=-4" from the command line, would she know to
check her configuration file?

If she had "grep.threads=Yes" in her configuration, we would
helpfully tell her that 'Yes' given to grep.threads is not a valid
integer.  Shouldn't we do the same for '-4' given to grep.threads,
too?

	if (!strcmp(var, "grep.threads")) {
		num_threads = git_config_int(var, value);
		if (num_threads < 0)
			die(_("invalid number of threads specified (%d) for %s"),
			    num_threads, var);
	}

perhaps.

> @@ -817,14 +827,23 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  	}
>  
>  #ifndef NO_PTHREADS
> -	if (list.nr || cached || online_cpus() == 1)
> -		use_threads = 0;
> +	if (list.nr || cached || online_cpus() == 1 || show_in_pager) {
> +		/* Can not multi-thread object lookup */
> +		num_threads = 0;

Removing 'use_threads = 0' from an earlier part and moving the check
to show_in_pager is a good idea, but it invalidates this comment.
The earlier three (actually two and a half) are "cannot" cases,
i.e. the object layer is not easily threaded without locking, and
when you have a single core, you do not truly run multiple
operations at the same time, but as [PATCH 2/2] does, threading in
"grep" is not about CPU alone, so that is why I am demoting it to
just a half ;-).  But show_in_pager is "we do not want to", I think.

In any case, this comment and "User didn't specify" below are not
telling the reader something very much useful.  You probably should
remove them.

> +	}
> +	else if (num_threads == 0) {
> +		/* User didn't specify value, or just wants default behavior */
> +		num_threads = GREP_NUM_THREADS_DEFAULT;
> +	}
> +	else if (num_threads < 0) {
> +		die(_("invalid number of threads specified (%d)"), num_threads);
> +	}

Many unnecessary braces.

I think [2/2] and also moving the code to disable threading when
show-in-pager mode should be separate "preparatory clean-up" patches
before this main patch.  I'll push out what I think this topic
should be on 'pu' later today (with fixups suggested above squashed
in); please check them and see what you think.

Thanks.

  reply	other threads:[~2015-12-15 20:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15 15:31 [PATCH v8 0/2] Add git-grep threads param Victor Leschuk
2015-12-15 15:31 ` [PATCH 1/2] Introduce grep " Victor Leschuk
2015-12-15 20:06   ` Junio C Hamano [this message]
2015-12-15 20:21     ` Victor Leschuk
2015-12-16  0:26     ` Eric Sunshine
2015-12-15 15:31 ` [PATCH 2/2] Get rid of online_cpus() when determining grep threads num Victor Leschuk

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq60zzfpdz.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=john@keeping.me.uk \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    --cc=vleschuk@accesssoftek.com \
    --cc=vleschuk@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).