From b2086b518366ed71caac498857b9c5765dd73ed1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 22 Jun 2021 12:04:50 -0400 Subject: log: avoid loading decorations for userformats that don't need it If no --decorate option is given, we default to auto-decoration. And when that kicks in, cmd_log_init_finish() will unconditionally load the decoration refs. However, if we are using a user-format that does not include "%d" or "%D", we won't show the decorations at all, so we don't need to load them. We can detect this case and auto-disable them by adding a new field to our userformat_want helper. We can do this even when the user explicitly asked for --decorate, because it can't affect the output at all. This patch consistently reduces the time to run "git log -1 --format=%H" on my git.git clone (with ~2k refs) from 34ms to 7ms. On a much more extreme real-world repository (with ~220k refs), it goes from 2.5s to 4ms. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pretty.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index b1ecd039ce..9631529c10 100644 --- a/pretty.c +++ b/pretty.c @@ -1735,6 +1735,10 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, case 'S': w->source = 1; break; + case 'd': + case 'D': + w->decorate = 1; + break; } return 0; } -- cgit v1.2.3