Skip to content

Commit a79e351

Browse files
rscharfegitster
authored andcommitted
commit: use prio_queue_replace() in pop_most_recent_commit()
Optimize pop_most_recent_commit() by adding the first parent using the more efficient prio_queue_peek() and prio_queue_replace() instead of prio_queue_get() and prio_queue_put(). On my machine this neutralizes the performance hit it took in Git's own repository when we converted it to prio_queue two patches ago (git_pq): $ hyperfine -w3 -L git ./git_2.50.1,./git_pq,./git '{git} rev-parse :/^Initial.revision' Benchmark 1: ./git_2.50.1 rev-parse :/^Initial.revision Time (mean ± σ): 1.073 s ± 0.003 s [User: 1.053 s, System: 0.019 s] Range (min … max): 1.069 s … 1.078 s 10 runs Benchmark 2: ./git_pq rev-parse :/^Initial.revision Time (mean ± σ): 1.077 s ± 0.002 s [User: 1.057 s, System: 0.018 s] Range (min … max): 1.072 s … 1.079 s 10 runs Benchmark 3: ./git rev-parse :/^Initial.revision Time (mean ± σ): 1.069 s ± 0.003 s [User: 1.049 s, System: 0.018 s] Range (min … max): 1.065 s … 1.074 s 10 runs Summary ./git rev-parse :/^Initial.revision ran 1.00 ± 0.00 times faster than ./git_2.50.1 rev-parse :/^Initial.revision 1.01 ± 0.00 times faster than ./git_pq rev-parse :/^Initial.revision Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d5091d commit a79e351

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

commit.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,17 +742,24 @@ void commit_list_sort_by_date(struct commit_list **list)
742742
struct commit *pop_most_recent_commit(struct prio_queue *queue,
743743
unsigned int mark)
744744
{
745-
struct commit *ret = prio_queue_get(queue);
745+
struct commit *ret = prio_queue_peek(queue);
746+
int get_pending = 1;
746747
struct commit_list *parents = ret->parents;
747748

748749
while (parents) {
749750
struct commit *commit = parents->item;
750751
if (!repo_parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {
751752
commit->object.flags |= mark;
752-
prio_queue_put(queue, commit);
753+
if (get_pending)
754+
prio_queue_replace(queue, commit);
755+
else
756+
prio_queue_put(queue, commit);
757+
get_pending = 0;
753758
}
754759
parents = parents->next;
755760
}
761+
if (get_pending)
762+
prio_queue_get(queue);
756763
return ret;
757764
}
758765

0 commit comments

Comments
 (0)