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

Re: [PATCH 3/3] contacts: reduce git-blame invocations

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 13, 2013, 21:10 UTC
Message-ID
<7veh9xwb3c.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1376084396-53617-4-git-send-email-sunshine@sunshineco.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 23 quoted lines
> git-contacts invokes git-blame once for each patch hunk it encounters.
> No attempt is made to consolidate invocations for multiple hunks
> referencing the same file at the same revision. This can become
> expensive quickly.
>
> Reduce the number of git-blame invocations by taking advantage of the
> ability to specify multiple -L ranges for a single invocation.
>
> Without this patch, on a randomly chosen range of commits:
>
>   % time git-contacts 25fba78d36be6297^..23c339c0f262aad2 >/dev/null
>   real  0m6.142s
>   user  0m5.429s
>   sys   0m0.356s
>
> With this patch:
>
>   % time git-contacts 25fba78d36be6297^..23c339c0f262aad2 >/dev/null
>   real  0m2.285s
>   user  0m2.093s
>   sys   0m0.165s
>
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Nice.  Will queue.
Show 34 quoted lines
> ---
>  contrib/contacts/git-contacts | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
> index b4d3526..fb6429b 100755
> --- a/contrib/contacts/git-contacts
> +++ b/contrib/contacts/git-contacts
> @@ -59,9 +59,11 @@ sub import_commits {
>  }
>  
>  sub get_blame {
> -	my ($commits, $source, $start, $len, $from) = @_;
> +	my ($commits, $source, $from, $ranges) = @_;
> +	return unless @$ranges;
>  	open my $f, '-|',
> -		qw(git blame --porcelain -C), '-L', "$start,+$len",
> +		qw(git blame --porcelain -C),
> +		map({"-L$_->[0],+$_->[1]"} @$ranges),
>  		'--since', $since, "$from^", '--', $source or die;
>  	while (<$f>) {
>  		if (/^([0-9a-f]{40}) \d+ \d+ \d+$/) {
> @@ -78,10 +80,7 @@ sub blame_sources {
>  	my ($sources, $commits) = @_;
>  	for my $s (keys %$sources) {
>  		for my $id (keys %{$sources->{$s}}) {
> -			for my $range (@{$sources->{$s}{$id}}) {
> -				get_blame($commits, $s,
> -					  $range->[0], $range->[1], $id);
> -			}
> +			get_blame($commits, $s, $id, $sources->{$s}{$id});
>  		}
>  	}
>  }
Previous: Eric Sunshine
Message 5 of 5 in “optimize git-contacts”
  1. 0/3 optimize git-contactsEric Sunshine, Aug 9, 2013
  2. 1/3 contacts: validate hunk length earlierEric Sunshine, Aug 9, 2013
  3. 2/3 contacts: gather all blame sources prior to invoking git-blameEric Sunshine, Aug 9, 2013
  4. 3/3 contacts: reduce git-blame invocationsEric Sunshine, Aug 9, 2013
  5. Junio C HamanoAug 13, 2013

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.