]> git.ipfire.org Git - thirdparty/git.git/commit
cat-file: skip expanding default format
authorJohn Cai <johncai86@gmail.com>
Tue, 15 Mar 2022 02:40:36 +0000 (02:40 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Mar 2022 17:15:32 +0000 (10:15 -0700)
commiteb54a3391bb3bdd6806ebffc21281eae8d9c0dca
tree84fe0c8ec07b5842f866f840f64080b3aa7a8106
parentc2162907e9aa884bdb70208389cb99b181620d51
cat-file: skip expanding default format

When format is passed into --batch, --batch-check, --batch-command,
the format gets expanded. When nothing is passed in, the default format
is set and the expand_format() gets called.

We can save on these cycles by hardcoding how to print the
information when nothing is passed as the format, or when the default
format is passed. There is no need for the fully expanded format with
the default. Since batch_object_write() happens on every object provided
in batch mode, we get a nice performance improvement.

git rev-list --all > /tmp/all-obj.txt

git cat-file --batch-check </tmp/all-obj.txt

with HEAD^:

Time (mean ± σ): 57.6 ms ± 1.7 ms [User: 51.5 ms, System: 6.2 ms]
Range (min … max): 54.6 ms … 64.7 ms 50 runs

with HEAD:

Time (mean ± σ): 49.8 ms ± 1.7 ms [User: 42.6 ms, System: 7.3 ms]
Range (min … max): 46.9 ms … 55.9 ms 56 runs

If nothing is provided as a format argument, or if the default format is
passed, skip expanding of the format and print the object info with a
default format.

See https://lore.kernel.org/git/87eecf8ork.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c
t/perf/p1006-cat-file.sh [new file with mode: 0755]