]> git.ipfire.org Git - thirdparty/git.git/commit
ref-filter: reuse output buffer
authorZheNing Hu <adlternative@gmail.com>
Tue, 20 Apr 2021 16:52:11 +0000 (16:52 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Apr 2021 18:09:50 +0000 (11:09 -0700)
commit844c3f0b0b5cc45f8aa8bd65c7ad407df7301c39
treee8571bed491c2669bd62f35241e3960139386b10
parent22f69a85edf29dba2278b55f14419e4ea48148d2
ref-filter: reuse output buffer

When we use `git for-each-ref`, every ref will allocate
its own output strbuf and error strbuf. But we can reuse
the final strbuf for each step ref's output. The error
buffer will also be reused, despite the fact that the git
will exit when `format_ref_array_item()` return a non-zero
value and output the contents of the error buffer.

The performance for `git for-each-ref` on the Git repository
itself with performance testing tool `hyperfine` changes from
23.7 ms ± 0.9 ms to 22.2 ms ± 1.0 ms. Optimization is relatively
minor.

At the same time, we apply this optimization to `git tag -l`
and `git branch -l`.

This approach is similar to the one used by 79ed0a5
(cat-file: use a single strbuf for all output, 2018-08-14)
to speed up the cat-file builtin.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Jeff King <peff@peff.net>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
builtin/for-each-ref.c
builtin/tag.c