From 62786f9a509a06ac031c066837d7a2285469677b Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 8 Aug 2026 12:49:54 -1000 Subject: Emit generated runs in batches, not a write each --- source/ui-tree.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source/ui-tree.c') diff --git a/source/ui-tree.c b/source/ui-tree.c index bc5986b..64be0b6 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -38,18 +38,31 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size) html("\n"); if (ctx.cfg.enable_tree_linenumbers) { + struct strbuf numbers = STRBUF_INIT; + html("\n"); } else { @@ -75,8 +88,6 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size) html("
");
 		idx = 0;
 		lineno = 0;
 
+		// Build the column in batches. A formatted write per line meant
+		// a syscall and a temporary buffer for every line of the file,
+		// which is most of what rendering a large blob cost, and the
+		// whole column at once would come to several times the blob.
 		if (size) {
-			htmlf(numberfmt, ++lineno);
+			strbuf_addf(&numbers, numberfmt, ++lineno);
 			while (idx < size - 1) { // skip absolute last newline
-				if (buf[idx] == '\n')
-					htmlf(numberfmt, ++lineno);
+				if (buf[idx] == '\n') {
+					strbuf_addf(&numbers, numberfmt, ++lineno);
+					if (numbers.len >= HTML_BATCH) {
+						html_raw(numbers.buf, numbers.len);
+						strbuf_reset(&numbers);
+					}
+				}
 				idx++;
 			}
+			html_raw(numbers.buf, numbers.len);
 		}
+		strbuf_release(&numbers);
 		html("
\n"); } -#define ROWLEN 32 - static void print_binary_buffer(char *buf, unsigned long size) { unsigned long ofs, idx; @@ -105,6 +116,7 @@ static void print_binary_buffer(char *buf, unsigned long size) html_txt(ascii); html("\n"); } + strbuf_release(&row); html("\n"); } @@ -393,7 +405,6 @@ static void ls_tree(const struct object_id *oid, const char *path, struct walk_t ls_tail(); } - static int walk_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) { -- cgit v2.8.0