Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Pablo Sabater <pabloosabaterr@gmail.com>
Cc: git@vger.kernel.org,  chandrapratap3519@gmail.com,
	 karthik.188@gmail.com
Subject: Re: [PATCH GSoC v2 4/6] fetch-object-info: parse type from server response
Date: Sat, 01 Aug 2026 06:38:38 -0700	[thread overview]
Message-ID: <xmqqzez67yg1.fsf@gitster.g> (raw)
In-Reply-To: <xmqq7bmaa0sw.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 31 Jul 2026 22:04:47 -0700")

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.

  reply	other threads:[~2026-08-01 13:38 UTC|newest]

Thread overview: 36+ 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-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 [this message]
2026-07-31 19:49   ` [PATCH GSoC v2 5/6] serve: advertise type capability Pablo Sabater
2026-08-01 12:12     ` Chandra Pratap
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=xmqqzez67yg1.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=chandrapratap3519@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=pabloosabaterr@gmail.com \
    /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