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

Re: [PATCH v2] cat-file: skip expanding default format

From
Taylor Blau <me@ttaylorr.com>
Date
Mar 8, 2022, 22:24 UTC
Message-ID
<YifXjuN27U53c46c@nand.local>
In-Reply-To
<YifSFQ8zEZimCkHl@nand.local>
On Tue, Mar 08, 2022 at 05:00:53PM -0500, Taylor Blau wrote:
> On my copy of git.git., it shaves off around ~7ms that we're spending
> just copying type names back and forth.

...while we're at it, I think we could go a little further and avoid doing the mark_query phase altogether, by doing something like:

--- 8< ---
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index ab9a49e13a..4b3cfb9e68 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -542,24 +542,30 @@ static int batch_objects(struct batch_options *opt)
 	int save_warning;
 	int retval = 0;

-	/*
-	 * Expand once with our special mark_query flag, which will prime the
-	 * object_info to be handed to oid_object_info_extended for each
-	 * object.
-	 */
-	memset(&data, 0, sizeof(data));
-	data.mark_query = 1;
-	strbuf_expand(&output,
-		      opt->format ? opt->format : DEFAULT_FORMAT,
-		      expand_format,
-		      &data);
-	data.mark_query = 0;
-	strbuf_release(&output);
 	if (opt->cmdmode)
 		data.split_on_whitespace = 1;

-	if (opt->format && !strcmp(opt->format, DEFAULT_FORMAT))
+	memset(&data, 0, sizeof(data));
+	if (!opt->format || !strcmp(opt->format, DEFAULT_FORMAT)) {
+		data.info.sizep = &data.size;
+		data.info.typep = &data.type;
+
 		opt->format = NULL;
+	} else {
+		/*
+		 * Expand once with our special mark_query flag, which will prime the
+		 * object_info to be handed to oid_object_info_extended for each
+		 * object.
+		 */
+		data.mark_query = 1;
+		strbuf_expand(&output,
+			      opt->format ? opt->format : DEFAULT_FORMAT,
+			      expand_format,
+			      &data);
+		data.mark_query = 0;
+		strbuf_release(&output);
+	}
+
 	/*
 	 * If we are printing out the object, then always fill in the type,
 	 * since we will want to decide whether or not to stream.

--- >8 ---

...but in my experiments it doesn't seem to help much. Or, at least, it
doesn't obviously help, there's too much noise from run to run for me to
see a worthwhile speed-up here.

Thanks,
Taylor
Previous: John CaiNext: John Cai
Message 11 of 17 in “cat-file: skip expanding default format”
  1. cat-file: skip expanding default formatJohn Cai via GitGitGadget, Mar 4, 2022
  2. Junio C HamanoMar 7, 2022
  3. Junio C HamanoMar 7, 2022
  4. John CaiMar 7, 2022
  5. Ævar Arnfjörð BjarmasonMar 7, 2022
  6. cat-file: skip expanding default formatJohn Cai via GitGitGadget, Mar 8, 2022
  7. Junio C HamanoMar 8, 2022
  8. John CaiMar 8, 2022
  9. Taylor BlauMar 8, 2022
  10. John CaiMar 8, 2022
  11. Taylor BlauMar 8, 2022
  12. John CaiMar 8, 2022
  13. cat-file: skip expanding default formatJohn Cai via GitGitGadget, Mar 8, 2022
  14. Taylor BlauMar 8, 2022
  15. John CaiMar 8, 2022
  16. John CaiMar 8, 2022
  17. cat-file: skip expanding default formatJohn Cai via GitGitGadget, Mar 15, 2022

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.