@matheusbsbs / matheus-bagliano / commits / 26a8ad25b2
Fork 0

show-branch: fix performance problem.

The core function used in show-branch, join_revs(), was supposed to be exactly the same algorithm as merge_bases(), except that it was a version enhanced for use with more than two heads. However, it needed to mark and keep a list of all the commits it has seen, because it needed them for its semi-graphical output. The function to implement this list, mark_seen(), stupidly used insert_by_date(), when it did not need to keep the list sorted during its processing. This made "show-branch --merge-base" more than 20x slower compared to "merge-base --all" in some cases (e.g. between b5032a5 and 48ce8b0 in the Linux 2.6 kernel archive). The performance of "show-branch --independent" suffered from the same reason. This patch sorts the resulting list after the list traversal just once to fix these problems. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 16, 2006 at 00:00 UTC 26a8ad25b28a1cb906c88bdf539d840774ca5aeb
1 file changed +5 -4
builtin-show-branch.c
+5 -4
@@ -172,7 +172,7 @@ static void name_commits(struct commit_list *list,
172 static int mark_seen(struct commit *commit, struct commit_list **seen_p)
173 {
174 if (!commit->object.flags) {
175 - insert_by_date(commit, seen_p);
175 + commit_list_insert(commit, seen_p);
176 return 1;
177 }
178 return 0;
@@ -218,9 +218,8 @@ static void join_revs(struct commit_list **list_p,
218 * Postprocess to complete well-poisoning.
219 *
220 * At this point we have all the commits we have seen in
221 - * seen_p list (which happens to be sorted chronologically but
222 - * it does not really matter). Mark anything that can be
223 - * reached from uninteresting commits not interesting.
221 + * seen_p list. Mark anything that can be reached from
222 + * uninteresting commits not interesting.
223 */
224 for (;;) {
225 int changed = 0;
@@ -701,6 +700,8 @@ int cmd_show_branch(int ac, const char **av, char **envp)
700 if (0 <= extra)
701 join_revs(&list, &seen, num_rev, extra);
702
703 + sort_by_date(&seen);
704 +
705 if (merge_base)
706 return show_merge_base(seen, num_rev);
707