git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] commit: convert pop_most_recent_commit() to prio_queue

From
René Scharfe <l.s.r@web.de>
Date
Jul 16, 2025, 09:39 UTC
Message-ID
<3f24210a-cd96-4c2c-9d55-1f0ebd7bbff5@web.de>
In-Reply-To
<d2myew7nonfrelrwplpypexvcrktmjdlsccobjvx3dydvhnlar@bin5ol2vj3xs>
On 7/15/25 10:47 PM, Justin Tobler wrote:
Show 6 quoted lines
> On 25/07/15 04:51PM, René Scharfe wrote:
>> pop_most_recent_commit() calls commit_list_insert_by_date(), which and
> 
> Did you mean?
> 
> s/which and/which/
Oh, yes.
Show 10 quoted lines
>> is itself called in a loop, which can lead to quadratic complexity.
>> Replace the commit_list with a prio_queue to ensure logarithmic worst
>> case complexity and convert all three users.
> 
> If I understand correctly, `pop_most_recent_commit()` removes the most
> recent commit from a list of commits sorted by date and then inserts
> each of the removed commit's parents into the list while maintaining
> date order. Iterating through `struct commit_list` every time to find
> where to insert each parent parent leads to quadratic complexity. For
> repositories with many merge commits, this could scale poorly.
Right.
Show 13 quoted lines
>> Add a performance test that exercises one of them using a pathological
>> history that consists of 50% merges and 50% root commits to demonstrate
>> the speedup:
>>
>>    Test                          v2.50.1           HEAD
>>    ----------------------------------------------------------------------
>>    1501.2: rev-parse ':/65535'   2.48(2.47+0.00)   0.20(0.19+0.00) -91.9%
>>
>> Alas, sane histories don't benefit from the conversion much, and
>> traversing Git's own history takes a 1% performance hit on my machine:
> 
> As "normal" repositories don't benefit here, it might be nice to more
> explicitly mention the the types of repositories that do benefit.
Good idea.
Show 23 quoted lines
>> diff --git a/commit.h b/commit.h
>> index 70c870dae4..9630c076d6 100644
>> --- a/commit.h
>> +++ b/commit.h
>> @@ -201,10 +201,10 @@ const char *repo_logmsg_reencode(struct repository *r,
>>  
>>  const char *skip_blank_lines(const char *msg);
>>  
>> -/** Removes the first commit from a list sorted by date, and adds all
>> - * of its parents.
>> - **/
>> -struct commit *pop_most_recent_commit(struct commit_list **list,
>> +struct prio_queue;
>> +
>> +/* Removes the first commit from a prio_queue and adds its parents. */
>> +struct commit *pop_most_recent_commit(struct prio_queue *queue,
>>  				      unsigned int mark);
> 
> Previously, `pop_most_recent_commit()` would ensure commits inserted in
> the list were done it date order. Now this depends on how the caller has
> configured the `struct prio_queue`. This is fine though as previously
> the caller was required to ensure the list was sorted to begin with
> otherwise it wouldn't work properly.
Indeed.
René
Previous: Justin ToblerNext: Jeff King
Message 5 of 41 in “commit: convert pop_most_recent_commit() to prio_queue”
  1. 0/3 commit: convert pop_most_recent_commit() to prio_queueRené Scharfe, Jul 15, 2025
  2. 1/3 commit: convert pop_most_recent_commit() to prio_queueRené Scharfe, Jul 15, 2025
  3. Junio C HamanoJul 15, 2025
  4. Justin ToblerJul 15, 2025
  5. René ScharfeJul 16, 2025
  6. Jeff KingJul 16, 2025
  7. René ScharfeJul 16, 2025
  8. René ScharfeJul 17, 2025
  9. Jeff KingJul 19, 2025
  10. Jeff KingJul 19, 2025
  11. René ScharfeJul 19, 2025
  12. Jeff KingJul 20, 2025
  13. Junio C HamanoJul 20, 2025
  14. Junio C HamanoJul 16, 2025
  15. René ScharfeJul 17, 2025
  16. 2/3 prio-queue: add prio_queue_replace()René Scharfe, Jul 15, 2025
  17. Jeff KingJul 16, 2025
  18. René ScharfeJul 16, 2025
  19. René ScharfeJul 17, 2025
  20. Jeff KingJul 19, 2025
  21. 3/3 commit: use prio_queue_replace() in pop_most_recent_commit()René Scharfe, Jul 15, 2025
  22. Junio C HamanoJul 15, 2025
  23. René ScharfeJul 16, 2025
  24. Junio C HamanoJul 16, 2025
  25. Jeff KingJul 16, 2025
  26. René ScharfeJul 16, 2025
  27. Jeff KingJul 19, 2025
  28. Junio C HamanoJul 16, 2025
  29. 0/3 commit: convert pop_most_recent_commit() to prio_queueRené Scharfe, Jul 18, 2025
  30. 1/3 commit: convert pop_most_recent_commit() to prio_queueRené Scharfe, Jul 18, 2025
  31. Lidong YanJul 21, 2025
  32. René ScharfeAug 3, 2025
  33. Junio C HamanoAug 3, 2025
  34. René ScharfeAug 4, 2025
  35. 3/3 commit: use prio_queue_replace() in pop_most_recent_commit(),MIME-Version: 1.0René Scharfe, Jul 18, 2025
  36. Johannes SchindelinAug 3, 2025
  37. René ScharfeAug 3, 2025
  38. 2/3 prio-queue: add prio_queue_replace()René Scharfe, Jul 18, 2025
  39. Jeff KingJul 19, 2025
  40. SZEDER GáborJul 22, 2025
  41. Junio C HamanoJul 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.