name-rev: use mem_pool_strfmt()
commitf39addd0d9d75a073847ed4311079a499dd33f35
authorRené Scharfe <l.s.r@web.de>
Sun, 25 Feb 2024 11:39:45 +0000 (25 12:39 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Feb 2024 17:35:40 +0000 (26 09:35 -0800)
tree863d6a1a179cfc971aa0274ea12204a54be99418
parent8d25663d704d1216d2fd5db5fd3aa431b8c58268
name-rev: use mem_pool_strfmt()

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/name-rev.c