Skip to contentSkip to conversation

commit-reach: stop sorting in paint_down_to_common()

PATCH In review René Scharfe 2 participants 4 messages May 27 – May 29

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commit-reach: stop sorting in paint_down_to_common()

None of the three callers of paint_down_to_common() care about the order of its result list: merge_bases_many() sorts it again after removing stale items, remove_redundant_no_gen() and repo_in_merge_bases_many() throw the list away without even looking at it. So drop the unnecessary commit_list_sort_by_date() call.

---
 commit-reach.c | 1 -
 1 file changed, 1 deletion(-)
commit-reach.c +0 -1
index 5a52be90a6..056a7ed8d8 100644
@@ -137,7 +137,6 @@ static int paint_down_to_common(struct repository *r,
 	}
 
 	clear_prio_queue(&queue);
-	commit_list_sort_by_date(result);
 	return 0;
 }
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 5 lines · René Scharfe

None of the three callers of paint_down_to_common() care about the order of its result list: merge_bases_many() sorts it again after removing stale items, remove_redundant_no_gen() and repo_in_merge_bases_many() throw the list away without even looking at it. So drop the unnecessary commit_list_sort_by_date() call.

Seems like an easy win. If some of the callers do not even look at the result, could we avoid building it at all in those cases (e.g., by passing in a NULL result pointer)?

I guess there is not much to be gained, though. The result is a list of merge bases, so it should usually be rather small. The benefit in your patch is probably not performance, but just reducing the size of the code.

-Peff

#2 lore raw
Quoted 11 lines · Jeff King
Quoted 5 lines · René Scharfe

None of the three callers of paint_down_to_common() care about the order of its result list: merge_bases_many() sorts it again after removing stale items, remove_redundant_no_gen() and repo_in_merge_bases_many() throw the list away without even looking at it. So drop the unnecessary commit_list_sort_by_date() call.

Seems like an easy win. If some of the callers do not even look at the result, could we avoid building it at all in those cases (e.g., by passing in a NULL result pointer)?

Yes, at the cost of adding NULL checks to paint_down_to_common(). Which is probably worth it.

Quoted 4 lines

I guess there is not much to be gained, though. The result is a list of merge bases, so it should usually be rather small. The benefit in your patch is probably not performance, but just reducing the size of the code.

True. The list can be arbitrarily long, but should only contain a handful commits in normal repos.

René

#3 lore raw
Quoted 6 lines · René Scharfe
Quoted 3 lines

Seems like an easy win. If some of the callers do not even look at the result, could we avoid building it at all in those cases (e.g., by passing in a NULL result pointer)?

Yes, at the cost of adding NULL checks to paint_down_to_common(). Which is probably worth it.

Yeah. I thought it was only one line (where we append to "tail"), but there are a couple spots where "result" is referenced directly.

Another fun fact: it looks like paint_down_to_common() makes sure to clean up the output list before returning an error. But the callers do so, too, which is redundant. That would go away if they just passed in NULL. :)

-Peff