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

Re: [PATCH] hash: reduce size of algo member of object ID

From
EWEric Wong <e@80x24.org>
Date
Oct 4, 2021, 07:31 UTC
Message-ID
<20211004073142.GA25608@dcvr>
In-Reply-To
<8da7bad2-b5a8-5aef-284b-dfa4e78556a9@web.de>
René Scharfe <l.s.r@web.de> wrote:
Show 6 quoted lines
> 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)) ).

Previous: René ScharfeNext: Jeff King
Message 2 of 7 in “hash: reduce size of algo member of object ID”
  1. hash: reduce size of algo member of object IDRené Scharfe, Oct 3, 2021
  2. Eric WongOct 4, 2021
  3. Jeff KingOct 4, 2021
  4. Jeff KingOct 4, 2021
  5. brian m. carlsonOct 5, 2021
  6. René ScharfeOct 5, 2021
  7. Ævar Arnfjörð BjarmasonOct 4, 2021

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.