Git development
 help / color / mirror / Atom feed
From: "Pablo Sabater" <pabloosabaterr@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>,
	"Pablo Sabater" <pabloosabaterr@gmail.com>
Cc: <git@vger.kernel.org>, <chandrapratap3519@gmail.com>,
	<karthik.188@gmail.com>, <peff@peff.net>
Subject: Re: [PATCH GSoC v2 4/6] fetch-object-info: parse type from server response
Date: Sun, 02 Aug 2026 00:20:28 +0200	[thread overview]
Message-ID: <DKDYGQRTSF2W.25OU81K306HJN@gmail.com> (raw)
In-Reply-To: <xmqqzez67yg1.fsf@gitster.g>

On Sat Aug 1, 2026 at 3:38 PM CEST, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> +		} else if (!strcmp(reader->line, "type")) {
>>> +			type_index = (int)i;
>>> +			for (size_t j = 0; j < args->oids->nr; j++)
>>> +				object_info_data[j].typep =
>>> +					xcalloc(1, sizeof(*object_info_data[j].typep));
>>
>> Do object_info_data[j].typep and object_info_data[k].typep need to
>> be independently freeable?  Separate allocations by calling calloc
>> args->oids->nr times would allow that, but if there is no such need,
>> nr contiguous allocation of them,
>
> Stepping back a bit, the design of "odb.h:struct object_info" look
> rather curious.
>
> Why does the struct store scalar values like "enum object_type" and
> "size_t" as a pointer to elsewhere, and does not store the values
> right there in the structure itself?  By forcing the caller to
> allocate an "enum object_type" for each of these object_info[]
> elements, the design requires 8-byte for a pointer to the heap and
> malloc overhead, probably ~16 bytes or more, in addition to store a
> single "enum object_type" that can be stored in a single byte.
>
> We are probably using this pointer indirection to say "ah, typep is
> NULL so the caller did not ask for this information and the object
> layer does not have to provide one", plus "typep is NULL so the
> engine did not give this information for the object".  But we can do
> so with two bitfields "unsigned typep_asked:1, typep_valid:1;"
> instead of paying ~24-byte or more heap allocation overhead.
>
> Again, this is not something we can change in the middle of this
> topic, but since I noticed it and found iffy, I'll leave a note here
> to stir the pot anyway.
>
> Stepping back a bit, the design of odb.h:struct object_info looks
> rather curious.
>
> Why does the struct store scalar values like enum object_type and
> size_t as pointers to elsewhere, rather than storing the values
> right there in the structure itself?  By forcing the caller to
> allocate an enum object_type for each of these object_info[]
> elements, the design requires an 8-byte pointer to the heap and
> malloc overhead, probably ~16 bytes or more, to store a single
> enum object_type that could fit in a single byte.
>
> We are probably using this pointer indirection to say "ah, '.typep'
> is NULL so the caller did not ask for this information and the
> object layer does not have to provide it", plus "'.typep' is NULL
> so the engine did not give this information for the object".  But we
> can do so with two bitfields
>
>     unsigned type_asked:1,
>              type_valid:1;
>
> instead of paying ~24 bytes or more of heap allocation overhead.
>
> Again, this is not something we can change in the middle of this
> topic, but since I noticed it and found it iffy, I'll leave a note
> here to stir the pot anyway.  It could be something we may want to
> clean-up much later after all the dust settles from this year's
> GSoC.  I dunno.

[CC'ing peff]

Hi!

I haven't stopped to think about that but it does look strange.

This is related to what had to be done to fix a bug at "contents"
commands a few days ago [1].

In that patch it had to save the previous state of typep and then
restore it, because other commands like "info" and this series one
"remote-object-info" use this pointer for the "is this asked?" question.

If we take a look at expand_atom():

	...
	} else if (is_atom("objecttype", atom, len)) {
		if (data->mark_query) {
			data->info.typep = &data->type;
		} else {
			const char *t = type_name(data->type);
			strbuf_addstr(sb, t ? t : "");
		}
	...

expand_atom() has two responsibilities, it is called at the start to map
which atoms are asked (when data->mark_query), and a second to expand
those atoms.

For example, typep being non-NULL does this effect on these commands:

info: makes a type lookup, and fills type.

remote-object-info: typep is directly used to know whether a client has
                    asked for %(objecttype).

For both commands what we pay is extra work because at the end the data
shown is the one expanded from the format.

It's out of scope for this series but I wanted to add what I know.

[1]: https://lore.kernel.org/git/20260728150031.GA41931@coredump.intra.peff.net/

Thanks,
Pablo

  reply	other threads:[~2026-08-01 22:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 11:55 [PATCH GSoC 0/5] cat-file: extend remote-object-info to support %(objecttype) Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 1/5] protocol-caps: add type support to object-info Pablo Sabater
2026-07-29  9:53   ` Chandra Pratap
2026-07-29 11:18     ` Pablo Sabater
2026-07-29 15:40     ` Junio C Hamano
2026-07-29 22:39   ` Karthik Nayak
2026-07-25 11:55 ` [PATCH GSoC 2/5] fetch-object-info: parse type from server response Pablo Sabater
2026-07-29  9:57   ` Chandra Pratap
2026-07-29 12:05     ` Pablo Sabater
2026-07-29 17:06       ` Chandra Pratap
2026-07-29 22:47   ` Karthik Nayak
2026-07-29 22:53     ` Karthik Nayak
2026-07-25 11:55 ` [PATCH GSoC 3/5] fetch-object-info: request all supported options dynamically Pablo Sabater
2026-07-29  9:57   ` Chandra Pratap
2026-07-29 12:07     ` Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 4/5] serve: advertise type capability Pablo Sabater
2026-07-29  9:58   ` Chandra Pratap
2026-07-29 12:15     ` Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 5/5] cat-file: unify default format Pablo Sabater
2026-07-29  9:59   ` Chandra Pratap
2026-07-29 12:23     ` Pablo Sabater
2026-07-29  9:52 ` [PATCH GSoC 0/5] cat-file: extend remote-object-info to support %(objecttype) Chandra Pratap
2026-07-29 12:34   ` Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 0/6] " Pablo Sabater
2026-07-31 19:49   ` [PATCH GSoC v2 1/6] fetch-object-info: request all supported options dynamically Pablo Sabater
2026-07-31 23:16     ` Junio C Hamano
2026-07-31 19:49   ` [PATCH GSoC v2 2/6] t5701: use the test_file_size() helper Pablo Sabater
2026-08-01  4:27     ` Junio C Hamano
2026-08-01 20:49       ` Pablo Sabater
2026-07-31 19:49   ` [PATCH GSoC v2 3/6] protocol-caps: add type support to object-info Pablo Sabater
2026-08-01  4:55     ` Junio C Hamano
2026-07-31 19:49   ` [PATCH GSoC v2 4/6] fetch-object-info: parse type from server response Pablo Sabater
2026-08-01  5:04     ` Junio C Hamano
2026-08-01 13:38       ` Junio C Hamano
2026-08-01 22:20         ` Pablo Sabater [this message]
2026-08-01 23:14           ` Jeff King
2026-08-01 23:29             ` Jeff King
2026-08-02  2:02               ` Junio C Hamano
2026-08-01 21:28       ` Pablo Sabater
2026-07-31 19:49   ` [PATCH GSoC v2 5/6] serve: advertise type capability Pablo Sabater
2026-08-01 12:12     ` Chandra Pratap
2026-08-01 21:30       ` Pablo Sabater
2026-07-31 19:49   ` [PATCH GSoC v2 6/6] cat-file: unify default format Pablo Sabater

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=DKDYGQRTSF2W.25OU81K306HJN@gmail.com \
    --to=pabloosabaterr@gmail.com \
    --cc=chandrapratap3519@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=peff@peff.net \
    /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