threads / patch / 58941

patchcommit: skip already cleared parents in clear_commit_marks_1()

Subject: [PATCH] commit: skip already cleared parents in clear_commit_marks_1()

## tl;dr

2 messages between Dec 13, 2022 and Dec 15, 2022. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Dec 13, 2022, 06:27 UTC · lore

Don't put clean parents on the pending list, as they and their ancestors don't need any treatment and would be skipped later anyway. This saves the allocation and release of a commit list item in ca. 20% of the cases during a run of the test suite.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 commit.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Show changes to commit.c +4 −3
diff --git a/commit.c b/commit.c
index 572301b80a..d00780bee5 100644
--- a/commit.c
+++ b/commit.c
@@ -701,8 +701,10 @@ static void clear_commit_marks_1(struct commit_list **plist,
 		if (!parents)
 			return;

-		while ((parents = parents->next))
-			commit_list_insert(parents->item, plist);
+		while ((parents = parents->next)) {
+			if (parents->item->object.flags & mark)
+				commit_list_insert(parents->item, plist);
+		}

 		commit = commit->parents->item;
 	}
--
2.38.2
Derrick Stolee· Dec 15, 2022, 15:13 UTC · re: René Scharfe · lore

Re: [PATCH] commit: skip already cleared parents in clear_commit_marks_1()

On 12/13/22 1:27 AM, René Scharfe wrote:
> Don't put clean parents on the pending list, as they and their ancestors
> don't need any treatment and would be skipped later anyway.  This saves
> the allocation and release of a commit list item in ca. 20% of the cases
> during a run of the test suite.
Show 6 quoted lines
> -		while ((parents = parents->next))
> -			commit_list_insert(parents->item, plist);
> +		while ((parents = parents->next)) {
> +			if (parents->item->object.flags & mark)
> +				commit_list_insert(parents->item, plist);
> +		}

From this context, it looks like this is a change of behavior (the walk only continues to parents that have the flag, so if the flag is not closed under reachability, such as the UNINTERESTING flag, then we won't clear all flags) but above this we already skip a commit that doesn't have the flag enabled.

One thing that is odd about this method is that it sets the 'commit' value to the first parent, and adds the later parents to the list. It's a minor point, but that check for the flag on the 'commit' is what prevents us from walking too far along the first-parent history.

All this to say, this is a safe change with a nice upside.

Thanks, -Stolee

← back to recent threads