git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] pack-objects: trace pack bytes written

From
friel@openai.com <friel@openai.com>
Date
Aug 19, 2026, 23:28 UTC
Message-ID
<c6a8cdac36d2202055d637ebcc97e484122cdcd4.1787158152.git.friel@openai.com>
In-Reply-To
<xmqqo6f02q2f.fsf@gitster.g>
From: Friel <friel@openai.com>

We want to measure how compression settings affect push performance on the client. Different settings can produce different-sized packs from the same objects. Trace2 records the object count, but we also need the pack size to compare those settings.

Add a write_pack_file/wrote_bytes Trace2 datum alongside write_pack_file/wrote. Count packs written to stdout or disk, including each pack's header and trailing checksum. When pack.packSizeLimit splits the output, report the sum of the pack sizes.

Signed-off-by: Friel <friel@openai.com>
---
Junio, you're right. Updating bytes_written before finalization is
equivalent. I've dropped pack_bytes; everything else is unchanged.
Thanks.
 builtin/pack-objects.c |  5 +++++
 t/t5300-pack-object.sh | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1ec5b6f206..252530172c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1337,6 +1337,7 @@ static void write_pack_file(void)
 	uint32_t nr_remaining = nr_result;
 	time_t last_mtime = 0;
 	struct object_entry **write_order;
+	off_t bytes_written = 0;
 
 	if (progress > pack_to_stdout)
 		progress_state = start_progress(the_repository,
@@ -1389,6 +1390,8 @@ static void write_pack_file(void)
 			display_progress(progress_state, written);
 		}
 
+		bytes_written += hashfile_total(f) +
+			the_repository->hash_algo->rawsz;
 		if (pack_to_stdout) {
 			/*
 			 * We never fsync when writing to stdout since we may
@@ -1510,6 +1513,8 @@ static void write_pack_file(void)
 		    written, nr_result);
 	trace2_data_intmax("pack-objects", the_repository,
 			   "write_pack_file/wrote", nr_result);
+	trace2_data_intmax("pack-objects", the_repository,
+			   "write_pack_file/wrote_bytes", bytes_written);
 }
 
 static int no_try_delta(const char *path)
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index 9dabb3615a..aac139e6a0 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -33,6 +33,30 @@ test_expect_success 'setup' '
 	} >expect
 '
 
+test_expect_success 'pack-object traces bytes written to stdout' '
+	test_when_finished "rm -f pack.trace pack.pack" &&
+	GIT_TRACE2_EVENT="$PWD/pack.trace" \
+		git pack-objects --quiet --revs --stdout >pack.pack <<-EOF &&
+	$commit
+	EOF
+	bytes=$(test_file_size pack.pack) &&
+	test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace
+'
+
+test_expect_success 'pack-object traces bytes written to split pack files' '
+	test_when_finished "rm -f split.trace traced-pack-*" &&
+	GIT_TRACE2_EVENT="$PWD/split.trace" \
+		git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack <obj-list &&
+	test 2 = $(ls traced-pack-*.pack | wc -l) &&
+	bytes=0 &&
+	for pack in traced-pack-*.pack
+	do
+		pack_size=$(test_file_size "$pack") &&
+		bytes=$((bytes + pack_size)) || return 1
+	done &&
+	test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" split.trace
+'
+
 test_expect_success 'setup pack-object <stdin' '
 	git init pack-object-stdin &&
 	test_commit -C pack-object-stdin one &&

Interdiff against v1:
  diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
  index bbf1adb437..252530172c 100644
  --- a/builtin/pack-objects.c
  +++ b/builtin/pack-objects.c
  @@ -1348,7 +1348,6 @@ static void write_pack_file(void)
   	do {
   		unsigned char hash[GIT_MAX_RAWSZ];
   		char *pack_tmp_name = NULL;
  -		off_t pack_bytes;
   
   		if (pack_to_stdout) {
   			/*
  @@ -1391,7 +1390,7 @@ static void write_pack_file(void)
   			display_progress(progress_state, written);
   		}
   
  -		pack_bytes = hashfile_total(f) +
  +		bytes_written += hashfile_total(f) +
   			the_repository->hash_algo->rawsz;
   		if (pack_to_stdout) {
   			/*
  @@ -1423,7 +1422,6 @@ static void write_pack_file(void)
   				write_bitmap_index = 0;
   			}
   		}
  -		bytes_written += pack_bytes;
   
   		if (!pack_to_stdout) {
   			struct stat st;

base-commit: 18e66859d87fb4b76599f73460b54f0848c76b16
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 3 of 11 in “pack-objects: trace pack bytes written”
  1. pack-objects: trace pack bytes writtenfriel@openai.com, Aug 17, 2026
  2. Junio C HamanoAug 18, 2026
  3. pack-objects: trace pack bytes writtenfriel@openai.com, Aug 19, 2026
  4. Patrick SteinhardtAug 20, 2026
  5. Jeff KingAug 20, 2026
  6. Patrick SteinhardtAug 20, 2026
  7. Jeff KingAug 21, 2026
  8. Junio C HamanoAug 21, 2026
  9. Junio C HamanoAug 20, 2026
  10. Jeff KingAug 21, 2026
  11. Junio C HamanoAug 21, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.