From: Derrick Stolee <stolee@gmail.com>
To: Kristofer Karlsson via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Cc: Kristofer Karlsson <krka@spotify.com>
Subject: Re: [PATCH] commit: remove padding from struct commit
Date: Thu, 12 Nov 2026 13:00:18 -0500 [thread overview]
Message-ID: <60c1d61e-777d-4c5a-b5a1-10c6530aa0d5@gmail.com> (raw)
In-Reply-To: <pull.2309.git.1794500044740.gitgitgadget@gmail.com>
On 11/12/2026 11:14 AM, Kristofer Karlsson via GitGitGadget wrote:
> 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
Good find.
> Reduce memory usage by moving .index into the hole after .object.
> On 64-bit platforms this shrinks the struct to 72 bytes and
> eliminates the padding, resulting in 10% less memory for every commit
> allocated, with no change in behaviour.
>
> On platforms where 8-byte members only need 4-byte alignment (e.g.
> i386) both layouts are already free of padding, so the size stays the
> same there.
>
> 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.
Thanks for measuring the memory load improvement. And of course this
won't have any impact on 32-bit machines as the struct will use
4-byte alignment by default.
> 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;
> };
This certainly looks like it should be obviously correct. I
believe that the only order-critical part is the object
struct needing to be first so we can "cast" a commit to an
object.
Thanks,
-Stolee
prev parent reply other threads:[~2026-11-12 18:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 16:14 [PATCH] commit: remove padding from struct commit Kristofer Karlsson via GitGitGadget
2026-11-12 18:00 ` Derrick Stolee [this message]
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=60c1d61e-777d-4c5a-b5a1-10c6530aa0d5@gmail.com \
--to=stolee@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=krka@spotify.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