git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: Jeff King <peff@peff.net>, git@vger.kernel.org
Cc: Derrick Stolee <dstolee@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 4/4] mark_parents_uninteresting(): avoid most allocation
Date: Mon, 14 May 2018 08:47:33 -0400	[thread overview]
Message-ID: <8447da69-d28a-433c-f324-a6380b6ca991@gmail.com> (raw)
In-Reply-To: <20180511180314.GD12543@sigill.intra.peff.net>

On 5/11/2018 2:03 PM, Jeff King wrote:
> Commit 941ba8db57 (Eliminate recursion in setting/clearing
> marks in commit list, 2012-01-14) used a clever double-loop
> to avoid allocations for single-parent chains of history.
> However, it did so only when following parents of parents
> (which was an uncommon case), and _always_ incurred at least
> one allocation to populate the list of pending parents in
> the first place.
>
> We can turn this into zero-allocation in the common case by
> iterating directly over the initial parent list, and then
> following up on any pending items we might have discovered.

This change appears to improve performance, but I was unable to measure 
any difference between this commit and the one ahead, even when merging 
ds/generation-numbers (which significantly reduces the other costs). I 
was testing 'git status' and 'git rev-list --boundary 
master...origin/master' in the Linux repo with my copy of master 70,000+ 
commits behind origin/master.

It's still a good change, but I was hoping to find a measurable benefit :(

>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Again, try "-w" for more readability.
>
>   revision.c | 44 +++++++++++++++++++++++++-------------------
>   1 file changed, 25 insertions(+), 19 deletions(-)
>
> diff --git a/revision.c b/revision.c
> index 89ff9a99ce..cbe041128e 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -115,32 +115,38 @@ static void commit_stack_clear(struct commit_stack *stack)
>   	stack->nr = stack->alloc = 0;
>   }
>   
> -void mark_parents_uninteresting(struct commit *commit)
> +static void mark_one_parent_uninteresting(struct commit *commit,
> +					  struct commit_stack *pending)
>   {
> -	struct commit_stack pending = COMMIT_STACK_INIT;
>   	struct commit_list *l;
>   
> +	if (commit->object.flags & UNINTERESTING)
> +		return;
> +	commit->object.flags |= UNINTERESTING;
> +
> +	/*
> +	 * Normally we haven't parsed the parent
> +	 * yet, so we won't have a parent of a parent
> +	 * here. However, it may turn out that we've
> +	 * reached this commit some other way (where it
> +	 * wasn't uninteresting), in which case we need
> +	 * to mark its parents recursively too..
> +	 */
>   	for (l = commit->parents; l; l = l->next)
> -		commit_stack_push(&pending, l->item);
> +		commit_stack_push(pending, l->item);
> +}
>   
> -	while (pending.nr > 0) {
> -		struct commit *commit = commit_stack_pop(&pending);
> +void mark_parents_uninteresting(struct commit *commit)
> +{
> +	struct commit_stack pending = COMMIT_STACK_INIT;
> +	struct commit_list *l;
>   
> -		if (commit->object.flags & UNINTERESTING)
> -			return;
> -		commit->object.flags |= UNINTERESTING;
> +	for (l = commit->parents; l; l = l->next)
> +		mark_one_parent_uninteresting(l->item, &pending);
>   
> -		/*
> -		 * Normally we haven't parsed the parent
> -		 * yet, so we won't have a parent of a parent
> -		 * here. However, it may turn out that we've
> -		 * reached this commit some other way (where it
> -		 * wasn't uninteresting), in which case we need
> -		 * to mark its parents recursively too..
> -		 */
> -		for (l = commit->parents; l; l = l->next)
> -			commit_stack_push(&pending, l->item);
> -	}
> +	while (pending.nr > 0)
> +		mark_one_parent_uninteresting(commit_stack_pop(&pending),
> +					      &pending);
>   
>   	commit_stack_clear(&pending);
>   }


  reply	other threads:[~2018-05-14 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11 18:00 [PATCH 0/4] a few mark_parents_uninteresting cleanups Jeff King
2018-05-11 18:00 ` [PATCH 1/4] mark_tree_contents_uninteresting(): drop missing object check Jeff King
2018-05-11 18:01 ` [PATCH 2/4] mark_parents_uninteresting(): " Jeff King
2018-05-13  2:23   ` Junio C Hamano
2018-05-11 18:02 ` [PATCH 3/4] mark_parents_uninteresting(): replace list with stack Jeff King
2018-05-11 18:03 ` [PATCH 4/4] mark_parents_uninteresting(): avoid most allocation Jeff King
2018-05-14 12:47   ` Derrick Stolee [this message]
2018-05-14 13:09     ` Jeff King
2018-05-14 13:25       ` Derrick Stolee
2018-05-14 14:09         ` Jeff King
2018-05-14 12:50 ` [PATCH 0/4] a few mark_parents_uninteresting cleanups Derrick Stolee

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=8447da69-d28a-433c-f324-a6380b6ca991@gmail.com \
    --to=stolee@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).