]> git.ipfire.org Git - thirdparty/git.git/commit
name-rev: pre-size buffer in get_parent_name()
authorRené Scharfe <l.s.r@web.de>
Tue, 4 Feb 2020 21:24:24 +0000 (22:24 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2020 18:24:15 +0000 (10:24 -0800)
commit1c56fc208400011b196f571041a0bc694fc9637c
tree22ec3e5b7dfdbc75309d9deca1bb9d46fc70de5d
parentddc42ec786ab2b64ef70bbd1e456db423dae031e
name-rev: pre-size buffer in get_parent_name()

We can calculate the size of new name easily and precisely. Open-code
the xstrfmt() calls and grow the buffers as needed before filling them.
This provides a surprisingly large benefit when working with the
Chromium repository; here are the numbers measured using hyperfine
before:

Benchmark #1: ./git -C ../chromium/src name-rev --all
  Time (mean ± σ):      5.822 s ±  0.013 s    [User: 5.304 s, System: 0.516 s]
  Range (min … max):    5.803 s …  5.837 s    10 runs

... and with this patch:

Benchmark #1: ./git -C ../chromium/src name-rev --all
  Time (mean ± σ):      1.527 s ±  0.003 s    [User: 1.015 s, System: 0.511 s]
  Range (min … max):    1.524 s …  1.535 s    10 runs

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/name-rev.c