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

Re: [PATCH 2/2] name-rev: use mem_pool_strfmt()

From
René Scharfe <l.s.r@web.de>
Date
Feb 26, 2024, 18:06 UTC
Message-ID
<53cfe0db-458e-4a43-b5ac-0c01cc6e79ea@web.de>
In-Reply-To
<xmqqfrxghtef.fsf@gitster.g>
Am 26.02.24 um 03:05 schrieb Junio C Hamano:
Show 36 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> 1c56fc2084 (name-rev: pre-size buffer in get_parent_name(), 2020-02-04)
>> got a big performance boost in an unusual repository by calculating the
>> name length in advance.  This is a bit awkward, as it references the
>> name components twice.
>>
>> Use a memory pool to store the strings for the struct rev_name member
>> tip_name.  Using mem_pool_strfmt() allows efficient allocation without
>> explicit size calculation.  This simplifies the formatting part of the
>> code without giving up performance:
>>
>> Benchmark 1: ./git_2.44.0 -C ../chromium/src name-rev --all
>>   Time (mean ± σ):      1.231 s ±  0.013 s    [User: 1.082 s, System: 0.136 s]
>>   Range (min … max):    1.214 s …  1.252 s    10 runs
>>
>> Benchmark 2: ./git -C ../chromium/src name-rev --all
>>   Time (mean ± σ):      1.220 s ±  0.020 s    [User: 1.083 s, System: 0.130 s]
>>   Range (min … max):    1.197 s …  1.254 s    10 runs
>>
>> Don't bother discarding the memory pool just before exiting.  The effort
>> for that would be very low, but actually measurable in the above
>> example, with no benefit to users.  At least UNLEAK it to calm down leak
>> checkers.  This addresses the leaks that 45a14f578e (Revert "name-rev:
>> release unused name strings", 2022-04-22) brought back.
>>
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>> ---
>> This doesn't make any test script leak-free, though.
>
> Hmph, is the root cause of the leak because no sensible ownership
> rules are applied to .tip_name?  Sometimes it is allocated for the
> paritcular rev_name, but some other times the pointer is copied from
> another rev_name.tip_name?  As the way currently the code uses the
> .tip_name member seems to be "allocate and use without any freeing",
> I tend to agree that throwing them into mem-pool does make sense.

Yes, the tip_name string is shared between child and first parent (and its first parent and so on, until a better name is found. Without this sharing the peak memory footprint of "git name-rev --all" in Git's repo goes from 40011328 to 46286528 for me currently.

I'm not too worried about the leak, though, as we can't release the memory until we're done anyway. The ability to build strings without having to calculate their sizes in advance (either by running vsnprintf twice, which is slow, or by doing format-specific calculations) is more interesting to me.

The reason why none of the test scripts become leak-free is other commands (i.e. not git name-rev) that are still leaking.

René
Previous: Junio C HamanoNext: René Scharfe
Message 4 of 10 in “name-rev: use memory pool for name strings”
  1. 0/2 name-rev: use memory pool for name stringsRené Scharfe, Feb 25, 2024
  2. 2/2 name-rev: use mem_pool_strfmt()René Scharfe, Feb 25, 2024
  3. Junio C HamanoFeb 26, 2024
  4. René ScharfeFeb 26, 2024
  5. 1/2 mem-pool: add mem_pool_strfmt()René Scharfe, Feb 25, 2024
  6. Jeff KingFeb 26, 2024
  7. René ScharfeFeb 26, 2024
  8. Jeff KingFeb 27, 2024
  9. René ScharfeFeb 27, 2024
  10. Jeff KingMar 7, 2024

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.