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

Re: [PATCH 2/8] fetch: move reference width calculation into `display_state`

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 17, 2023, 10:03 UTC
Message-ID
<ZBQ612KWqYg4ky2j@ncase>
In-Reply-To
<xmqqpm98mzzy.fsf@gitster.g>
On Thu, Mar 16, 2023 at 09:18:09AM -0700, Junio C Hamano wrote:
Show 28 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> >> Given that in the previous step, what used to be called display got
> >> renamed to display_buffer (I think "buffer" ought to be sufficient
> >> in this context, though), the variable of "struct display_state"
> >> type should NOT be named "display", as it would be confusing when
> >> two things are related to "display" and only one of them is called
> >> as such.  Either "display_state" or "state" would be fine.
> >
> > Fair enough. In that case I may just as well drop the first patch.
> 
> If you plan to get rid of an independent "display_buffer" in the
> endgame by moving it into the bigger struct as its .buffer member,
> then I think the naming is fine as there will remain only one thing
> that is "display".  The fact that I didn't see that plan through
> when I read only the first two patches would probably mean that the
> route this iteration of the series took was somewhat roundabout, and
> there may be a more transparent and possibly a more direct way to
> get to that goal?
> 
> I am not entirely sure if the buffer should go inside the
> display_state structure in the endgame.  An alternative may be to
> make it a on-stack variable of format_display() (which will later be
> modified to do everything up to and including writing out the
> result) and pass it through the callchain below to its helpers, just
> like the current code already does.  And in such an approach, you'd
> still need to name that variable passed to the helper functions
> called by format_display()---"buffer" would be a good name for that.

Well, we could make it an on-stack variable just fine. But I suspect that the only reason that this buffer exists is to optimize memory allocations: a git-fetch(1) can easily end up printing thousands or even hundreds of thousands of updated references, and reallocating that buffer for each of them is quite wasteful.

Another alternative would be to make the buffer static and local to the function. But you now have shared state again, and furthermore you have no easy way to unleak its contents.

In the end, I think that having the buffer as a member of the display state is the most straight-forward approach. It's self-contained and allows us to reduce the number of allocations to a minimum. That being said, I'm obviously biased here.

Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 39 in “fetch: refactor code that prints reference updates”
  1. 0/8 fetch: refactor code that prints reference updatesPatrick Steinhardt, Mar 15, 2023
  2. 1/8 fetch: rename `display` buffer to avoid name conflictPatrick Steinhardt, Mar 15, 2023
  3. 2/8 fetch: move reference width calculation into `display_state`Patrick Steinhardt, Mar 15, 2023
  4. Junio C HamanoMar 15, 2023
  5. Patrick SteinhardtMar 16, 2023
  6. Junio C HamanoMar 16, 2023
  7. Patrick SteinhardtMar 17, 2023
  8. Junio C HamanoMar 16, 2023
  9. 3/8 fetch: move output format into `display_state`Patrick Steinhardt, Mar 15, 2023
  10. 4/8 fetch: pass the full local reference name to `format_display`Patrick Steinhardt, Mar 15, 2023
  11. Junio C HamanoMar 15, 2023
  12. 5/8 fetch: deduplicate handling of per-reference formatPatrick Steinhardt, Mar 15, 2023
  13. Junio C HamanoMar 15, 2023
  14. Patrick SteinhardtMar 16, 2023
  15. Junio C HamanoMar 16, 2023
  16. Patrick SteinhardtMar 17, 2023
  17. Junio C HamanoMar 17, 2023
  18. 7/8 fetch: fix inconsistent summary width for pruned and updated refsPatrick Steinhardt, Mar 15, 2023
  19. Junio C HamanoMar 15, 2023
  20. Patrick SteinhardtMar 16, 2023
  21. Junio C HamanoMar 16, 2023
  22. Patrick SteinhardtMar 17, 2023
  23. 6/8 fetch: deduplicate logic to print remote URLPatrick Steinhardt, Mar 15, 2023
  24. Junio C HamanoMar 15, 2023
  25. Patrick SteinhardtMar 16, 2023
  26. 8/8 fetch: centralize printing of reference updatesPatrick Steinhardt, Mar 15, 2023
  27. Jonathan TanMar 17, 2023
  28. Patrick SteinhardtMar 20, 2023
  29. Patrick SteinhardtMar 20, 2023
  30. 0/6 fetch: refactor code that prints reference updatesPatrick Steinhardt, Mar 20, 2023
  31. 1/6 fetch: move reference width calculation into `display_state`Patrick Steinhardt, Mar 20, 2023
  32. 2/6 fetch: move output format into `display_state`Patrick Steinhardt, Mar 20, 2023
  33. 3/6 fetch: pass the full local reference name to `format_display`Patrick Steinhardt, Mar 20, 2023
  34. 4/6 fetch: centralize handling of per-reference formatPatrick Steinhardt, Mar 20, 2023
  35. 5/6 fetch: centralize logic to print remote URLPatrick Steinhardt, Mar 20, 2023
  36. 6/6 fetch: centralize printing of reference updatesPatrick Steinhardt, Mar 20, 2023
  37. Jonathan TanMar 20, 2023
  38. Patrick SteinhardtMar 22, 2023
  39. Junio C HamanoMar 29, 2023

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.