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

Re: [PATCH] commit: remove padding from struct commit

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 12, 2026, 19:22 UTC
Message-ID
<xmqqpkw9j1ng.fsf@gitster.g>
In-Reply-To
<pull.2309.git.1794500044740.gitgitgadget@gmail.com>

"Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 30 quoted lines
> From: Kristofer Karlsson <krka@spotify.com>
>
> On 64-bit platforms, "struct commit" is 80 bytes, 8 of which are
> padding:
>  - 4 bytes between .object and .date
>  - 4 bytes of tail padding after .index
> ...
> Measuring peak RSS of "git rev-list --all" over an internal monorepo
> with ~4.5 million commits (three runs each):
>
>              peak RSS     time
>   before     ~849 MiB   12.8-13.7s
>   after      ~817 MiB   12.8-13.0s
>
> The ~32 MiB saved is close to the expected 8 bytes * 4.5M commits
> (~34 MiB); running time is unchanged within noise.
>
> Signed-off-by: Kristofer Karlsson <krka@spotify.com>
> ---
>     I also prototyped a regression test that compares the size of "struct
>     commit" and "struct object" against the sum of their members' sizes,
>     plus any expected padding. I left it out of this patch because I am not
>     sure whether:
>     
>      1. such a test is worth the cost of updating it whenever members are
>         added or removed, or
>     
>      2. a unit test is the right place for it.
>     
>     I am happy to send it as a follow-up if there is interest.
The comment before this structure says ...
Show 6 quoted lines
> diff --git a/commit.h b/commit.h
> index 1061ed791b..66a5d245f2 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -26,6 +26,7 @@ struct commit_list {
>   */
/*
 * The size of this struct matters in full repo walk operations like
 * 'git clone' or 'git gc'. Consider using commit-slab to attach data
 * to a commit instead of adding new fields here.
 */

but apparently it did not have much effect to prevent this from happening.

I would think it is an effective way to force people to think struct size bloat of important and populous structure to always measure and warn. There may be better ways to achieve the same that others may think of, but I very much appreciate your bringing it up, even only as a discussion starter.

Show 12 quoted lines
>  struct commit {
>  	struct object object;
> +	unsigned int index;
>  	timestamp_t date;
>  	struct commit_list *parents;
>  
> @@ -35,7 +36,6 @@ struct commit {
>  	 * or get_commit_tree_oid().
>  	 */
>  	struct tree *maybe_tree;
> -	unsigned int index;
>  };

Obviously, ordering members based on size, not their logical relationships, has its downside. The "object" being at offset 0 is an integral part of our in-core object design (fake inheritance in C), but the updated layout gives a false sense that somehow "index" may have a more important meaning than say "date" or "parents".

We may want to have some comments next to "index" (which is a unique number given to all in-core commits while they are held in memory, to allow the commit slab subsystem to use it as an index into flat array of things) and "date" (which is the committer date taken from the underlying commit object, without any adjustment), which are two of these members whose meanings are not immediately obvious.

Previous: Kristofer KarlssonNext: Kristofer Karlsson
Message 4 of 12 in “commit: remove padding from struct commit”
  1. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 12, 2026
  2. Derrick StoleeNov 12, 2026
  3. Kristofer KarlssonNov 12, 2026
  4. Junio C HamanoNov 12, 2026
  5. Kristofer KarlssonNov 12, 2026
  6. Oswald BuddenhagenNov 13, 2026
  7. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 13, 2026
  8. Derrick StoleeNov 13, 2026
  9. Kristofer KarlssonNov 13, 2026
  10. Junio C HamanoNov 13, 2026
  11. Junio C HamanoNov 13, 2026
  12. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 15, 2026

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.