Re: [PATCH] hash: reduce size of algo member of object ID
flat view
From: Eric Wong <hidden>
Date: 2021-10-04 07:31:45
René Scharfe [off-list ref] wrote:
cf0983213c (hash: add an algo member to struct object_id, 2021-04-26) introduced the algo member as an int. This increased the size of struct object_id by 4 bytes (12.5%) and imposed a 4-byte alignment. Currently we only need to stored the values 0, 1 and 2 in it. Let's use an unsigned char instead to reduce the size overhead and lift the alignment requirement.
I like it. Btw, would a bitfield enum be portable enough for us? enum git_hash_algo algo:8; /* or algo:2 */ I've used those in other projects, but AFAIK they were for gcc||clang-only.
Not sure how to measure the performance impact of this change. The perf tests mentioned by cf0983213c don't show much of a difference with GIT_PERF_REPEAT_COUNT=10 for me:
Thanks for that info. I'm not familiar enough with most git internals to know if it ought to make a difference as-is. In my experience, changes like this open the door to further struct-packing opportunities (possibly combined with conditional use of __attribute__((packed)) ).