Git development
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: git@vger.kernel.org
Subject: [PATCH 2/4] cat-file: use strbuf_add_uint()
Date: Tue, 12 May 2026 13:56:01 +0200	[thread overview]
Message-ID: <20260512115603.80780-3-l.s.r@web.de> (raw)
In-Reply-To: <20260512115603.80780-1-l.s.r@web.de>

Speed up printing of objectsize atoms by using the specialized function
strbuf_add_uint() instead of the general-purpose function strbuf_addf():

Benchmark 1: ./git_main cat-file --batch-all-objects --batch-check='%(objectsize)'
  Time (mean ± σ):     751.7 ms ±   1.5 ms    [User: 733.5 ms, System: 17.1 ms]
  Range (min … max):   750.5 ms … 755.0 ms    10 runs

Benchmark 2: ./git cat-file --batch-all-objects --batch-check='%(objectsize)'
  Time (mean ± σ):     720.4 ms ±   0.4 ms    [User: 701.9 ms, System: 16.7 ms]
  Range (min … max):   719.7 ms … 721.2 ms    10 runs

Summary
  ./git cat-file --batch-all-objects --batch-check='%(objectsize)' ran
    1.04 ± 0.00 times faster than ./git_main cat-file --batch-all-objects --batch-check='%(objectsize)'

Benchmark 1: ./git_main cat-file --batch-all-objects --batch-check='%(objectsize:disk)'
  Time (mean ± σ):     404.6 ms ±   0.9 ms    [User: 397.8 ms, System: 5.7 ms]
  Range (min … max):   403.3 ms … 405.9 ms    10 runs

Benchmark 2: ./git cat-file --batch-all-objects --batch-check='%(objectsize:disk)'
  Time (mean ± σ):     378.3 ms ±   0.9 ms    [User: 371.2 ms, System: 5.9 ms]
  Range (min … max):   376.8 ms … 380.2 ms    10 runs

Summary
  ./git cat-file --batch-all-objects --batch-check='%(objectsize:disk)' ran
    1.07 ± 0.00 times faster than ./git_main cat-file --batch-all-objects --batch-check='%(objectsize:disk)'

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/cat-file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d9fbad5358..62160ca9d4 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -330,12 +330,12 @@ static int expand_atom(struct strbuf *sb, const char *atom, int len,
 		if (data->mark_query)
 			data->info.sizep = &data->size;
 		else
-			strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size);
+			strbuf_add_uint(sb, data->size);
 	} else if (is_atom("objectsize:disk", atom, len)) {
 		if (data->mark_query)
 			data->info.disk_sizep = &data->disk_size;
 		else
-			strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size);
+			strbuf_add_uint(sb, data->disk_size);
 	} else if (is_atom("rest", atom, len)) {
 		if (data->mark_query)
 			data->split_on_whitespace = 1;
-- 
2.54.0


  parent reply	other threads:[~2026-05-12 11:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 11:55 [PATCH 0/4] strbuf: add and use strbuf_add_uint() René Scharfe
2026-05-12 11:56 ` [PATCH 1/4] strbuf: add strbuf_add_uint() René Scharfe
2026-05-12 18:42   ` Jeff King
2026-05-12 19:32     ` René Scharfe
2026-05-13 16:22       ` Jeff King
2026-05-13 16:47         ` Jeff King
2026-05-13 16:49         ` Jeff King
2026-05-14 11:09           ` René Scharfe
2026-05-14 11:53             ` Junio C Hamano
2026-05-15  3:53             ` Jeff King
2026-05-13 17:46         ` René Scharfe
2026-05-12 11:56 ` René Scharfe [this message]
2026-05-12 18:46   ` [PATCH 2/4] cat-file: use strbuf_add_uint() Jeff King
2026-05-12 11:56 ` [PATCH 3/4] ls-files: " René Scharfe
2026-05-12 19:01   ` Jeff King
2026-05-12 20:44     ` René Scharfe
2026-05-13 16:46       ` Jeff King
2026-05-12 11:56 ` [PATCH 4/4] ls-tree: " René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260512115603.80780-3-l.s.r@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox