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

Re: [PATCH] upload-pack: add tracing for fetches

From
Jeff King <peff@peff.net>
Date
Oct 11, 2023, 22:27 UTC
Message-ID
<20231011222728.GC518221@coredump.intra.peff.net>
In-Reply-To
<pull.1598.git.1697040242703.gitgitgadget@gmail.com>
On Wed, Oct 11, 2023 at 04:04:02PM +0000, Robert Coup via GitGitGadget wrote:
Show 7 quoted lines
> Improve this by emitting a Trace2 JSON event from upload-pack with
> summary information on the contents of a fetch request.
> 
> * haves, wants, and want-ref counts can help determine (broadly) between
>   fetches and clones, and the use of single-branch, etc.
> * shallow clone depth, tip counts, and deepening options.
> * any partial clone filter type.

I think this is a reasonable thing to have. I see Taylor left a more detailed review, but I did notice one thing...

Show 25 quoted lines
> +static void trace2_fetch_info(struct upload_pack_data *data)
> +{
> +	struct json_writer jw = JSON_WRITER_INIT;
> +
> +	jw_object_begin(&jw, 0);
> +	{
> +		jw_object_intmax(&jw, "haves", data->haves.nr);
> +		jw_object_intmax(&jw, "wants", data->want_obj.nr);
> +		jw_object_intmax(&jw, "want-refs", data->wanted_refs.nr);
> +		jw_object_intmax(&jw, "depth", data->depth);
> +		jw_object_intmax(&jw, "shallows", data->shallows.nr);
> +		jw_object_bool(&jw, "deepen-since", data->deepen_since);
> +		jw_object_intmax(&jw, "deepen-not", data->deepen_not.nr);
> +		jw_object_bool(&jw, "deepen-relative", data->deepen_relative);
> +		if (data->filter_options.choice)
> +			jw_object_string(&jw, "filter", list_object_filter_config_name(data->filter_options.choice));
> +		else
> +			jw_object_null(&jw, "filter");
> +	}
> +	jw_end(&jw);
> +
> +	trace2_data_json("upload-pack", the_repository, "fetch-info", &jw);
> +
> +	jw_release(&jw);
> +}

Generating the json output isn't entirely trivial (and certainly involves allocations), but we throw it away unused if tracing isn't enabled. Maybe we'd want something like:

  if (!trace2_is_enabled())
          return;

at the top of the function? It looks like other callers of jw_object_begin() have a similar issue, and this is probably premature optimization to some degree. It just feels like it should be easy for tracing to be zero-cost (beyond a single conditional) when it's disabled.

-Peff
Previous: Robert CoupNext: Robert Coup
Message 5 of 10 in “upload-pack: add tracing for fetches”
  1. upload-pack: add tracing for fetchesRobert Coup via GitGitGadget, Oct 11, 2023
  2. Taylor BlauOct 11, 2023
  3. Taylor BlauOct 11, 2023
  4. Robert CoupOct 11, 2023
  5. Jeff KingOct 11, 2023
  6. Robert CoupOct 11, 2023
  7. upload-pack: add tracing for fetchesRobert Coup via GitGitGadget, Oct 17, 2023
  8. Robert CoupOct 23, 2023
  9. Jeff KingOct 23, 2023
  10. Taylor BlauOct 30, 2023

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.