Repository navigation
pr-2309/spkrka/commit-index-hole-v2
tagged this
13 Nov 13:30
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
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.
Since the order of the members no longer reflects their importance,
document that only "object" has to come first, and describe "index"
and "date", whose meanings are not obvious from their names.
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>
Submitted-As: https://lore.kernel.org/git/pull.2309.v2.git.1794576606249.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2309.git.1794500044740.gitgitgadget@gmail.com