Article View: linux.kernel.git
Article #2994[PATCH] commit: remove padding from struct commit
From: "Kristofer Karlsson via GitGitGa...
Date: Thu, 12 Nov 2026 16:14
Date: Thu, 12 Nov 2026 16:14
81 lines
13068 bytes
13068 bytes
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.
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>
---
commit: remove padding from struct commit
I stumbled on this while rabbit-holing on an unrelated change to the
commit walk, by looking at the layout with gdb's "ptype /o".
Digging into the history showed that the size and padding of "struct
commit" have changed several times, sometimes undoing earlier
optimizations.
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.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2309%2Fspkrka%2Fcommit-index-hole-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2309/spkrka/commit-index-hole-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2309
commit.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 {
*/
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;
};
extern int save_commit_buffer;
base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
--
gitgitgadget
Technical Details
Message-ID:
<pull.2309.git.1794500044740.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75289-linux-kernel-git=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75289-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Kristofer Karlsson via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH] commit: remove padding from struct commit
Date: Thu, 12 Nov 2026 16:14:04 +0000
Organization: Usenet Network
Message-ID: <pull.2309.git.1794500044740.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1125192"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:EjGcKTXlLNlFOU15NZ8MAL/kq7Y= sha256:S1kBAm/PiU293kbc718DyC89swY+ZPm9SIY5ie52loo=
sha1:ijywQsI7gmC0nlBzt7Z38RKMPt8= sha256:Dm11TQvJBjHeiMVaY/JGBD6IOpEAq2gb/5LTqtGoJB0=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 35AC01142EA; Thu, 12 Nov 2026 19:29:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id e9Z_Xd9Yfgcb;
Thu, 12 Nov 2026 19:29:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-75289-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 5311C1142D4; Thu, 12 Nov 2026 19:29:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 6B92FC4AFB; Thu, 12 Nov 2026 16:14:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794500049;
b=RmGABJa4/5ogNhpDIsWZR23yIG+WCoF2mhjNx3PYe3+mHA/6+9XZPEHHGJbqE+sjKDGv
Q3UFZLkq+OsgK91hDAUOW4xK5Tas2Sxhe2w7ijq87s6VxGjAjVHlx67UiTRq7/296XWOI
W7eqQWUDU2uwk3UQ70TOxEPHx7uBEhBRkyKIaoQhbfQgEX/vXTK0WXx+k22edH9jBwJaH
Xnu1YQWM+ZZMTB824ogwmyy5yEgZ6CKHVDbRwBf3M04WrwmnG08w/cdOTt0awZtP/4PPL
vDJixOyD3966HtdbkTtMlXuvrRls0Gi6Z9NG6R2sW8eYh1aXTGRlf+cbQauQmNhkvbg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794500049;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-Id:From:Date:Subject:Fcc:Content-Type:
Content-Transfer-Encoding:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:To:
Cc;
bh=xdQfxFO51Lm3kYux66foco3nTodpeyX2LHKvNq+iLKc=;
b=F9NWxd4ITEwaeo2hLl8JkunEoD+m2JAjzADWXTSNnbOOxS7X/Z7PXb4taJpwMTo/n6zT
X6M8bS+Yj0g0gyquDO2/mDhPQxmbmIkgdGcyPHQx91pM9ocdUJKd5VZwdSfHKJi/uXsF3
zoP7ZaHJBFLKZ0jVdD5S7I5K9ylG97mDJ6y94DD3RoEL5bbwdR932bTrsTFeJOJg+cEfT
Y3uWysJiEPuTM32TQyNVGwT+AjaKc+SC3scYiUuOObzDQ0zkma7qvGEurfz3DhbmndKMi
zTyq6zVViRb673eo+N4xUuQVcLpwXuntsarK2PYz4mgDmkvswKGT0lTX5X3O83ZnIMA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yGhqzSah;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id DDC62606A32A;
Thu, 12 Nov 2026 16:14:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yGhqzSah
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794500048;
b=ZjzfbWgnBX4Ra8KAu60AGWIptzqGZh6IOt6DHuhKulMqJYVmbmMMcl1NifUKhe/uQT38
i3ctY4yGbkbRFe8lSOY9HX6xqnviFdIjOj+mJ5BZa0yFeyYI5w8O1K7rv0x1eLKNU5oSV
VoGy+tkmHh1pA/6rjGigu7G4V02SQx2w73p7Hs5jQNLsnY0NqRnYbpdrUahIUqGOoazud
50MDJ/Bbb3bBHBGVO/1+viNE/sZSOA4s81bck4+xBmFMYB2uFmlInGiW/h/EI0wiSxC/g
5iT33B/Jtq3B9fGup5QjEiIitlOhq1Kr0sk0zJpho2Oc701+SCXIuTTUaVK93FbKXOA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794500048;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:From:Date:
Subject:Fcc:Content-Type:Content-Transfer-Encoding:MIME-Version:To:
Cc;
bh=xdQfxFO51Lm3kYux66foco3nTodpeyX2LHKvNq+iLKc=;
b=joDrvEZ2gAT387TzzUhSedjhuEMlwlyhoBl2iWpoFdITZH4nykkSJgg+JmSMylyp49UR
tYwUwyckgZb48ku+WWLZJLViQ50MtPtS0KYSAs1Zcix/M82JH2OqPOqlfupeZFnOmQvbc
r1ulSpWOZYSkcM53fscORWivL8cgyow7xzTLAxZ5UsQXU3zP17rDPbE1TsVyT6ZBue1E7
Daw4Dhh96EBMrq4xRpDPzwQ142Dy/QPAqjiZNOPMI9Xj1cEAPdtB2lvJhyOIZb86dO1U8
mrXAiklorWlVfoGGq1YLpj5VNdJITgAkFNFzNQ73YnWUXsepvKfFbDKmlZZlWj57IXQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yGhqzSah;
arc=none smtp.remote-ip=74.125.82.179
X-Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC1A1606A331
for <git@vger.kernel.org>; Thu, 12 Nov 2026 16:14:07 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC1A1606A331
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-37000e7234bso35836eec.1
for <git@vger.kernel.org>; Thu, 12 Nov 2026 08:14:07 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794500047; x=1795104847; darn=vger.kernel.org;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:message-id:from:to:cc:subject:date:message-id
:reply-to:content-type;
bh=xdQfxFO51Lm3kYux66foco3nTodpeyX2LHKvNq+iLKc=;
b=yGhqzSah/u8TktLbTCa/+T+9Td+Qb9cMHI4MSO6wUXrlp9ua6YuFYHfo7D34n3vi0r
AC0txvSzRtc8J+Whjx8PAc3msXr77mboaL1+nI06Q+rEo0vshfsKniniodIO7U+0wvf4
DvH4jWn7jUwdL162+CXiAZbVA4NWSqjIvztxw9mF3zSIc6weFwFNOgChFBVPhHJWbF1X
MDZvAj4pjEzGrjRsdbGyWJgZsCmE4JnCdFJaINu9wcTd2S35vks/DfpPV81/RYJIp+hk
DBZGot3pUjjALypn7qsSrfROVWPS7F2GeEMfhWCnrAMVYBF1U4Zxl8xT7LowKYb4rdHG
Kxjg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794500047; x=1795104847;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:message-id:x-gm-gg:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=xdQfxFO51Lm3kYux66foco3nTodpeyX2LHKvNq+iLKc=;
b=oWn/7xWZUPGgtICWruq/qsaWCyglW/ZJrrdXN9lwEjMmvTUqgkosgMEma8KPrjpP/0
5LtEF0H2OMCGN4ele8r3iezAwvi+MCncQYcSMtrEr+8UHyAYrSkOjdIyCkR+21cCbYcd
aNNOHHvP8qXHgQntW+dhBHwOPN/mEWXFguM/hYCzN9Ix8BE3j95q3S2Sdh0Ro1eGMBQG
QzOweRFt4vCmnwPRpVxbghlESOVE2LLQarV16l1Ul26Rr0HspWqroRh78wfIdMNoM5Mj
eLZqYweNRsaUZ3ahcOTuJHf5d7BFD67JMhsiRySBvYKDjcVKimx700ANWJpYLVy640OV
ILGA==
X-Gm-Message-State: APuU4Z/KXgIM+bkKLypDKVpJcfWWb6v7p9B5KU6RoqZcPuFyqqEy2joU
CPU5OiWY89wEMSWQtARTiViSYRU5vDJgzraVCKfRX4UFuVwYeRIs14U+dkVFaA==
X-Gm-Gg: AYBFou3E/ltI35kbt5E3UIAgh3Wtp7o3N0cnZioEFw/l/e0cCE5nInJ39AJQKLhBOzR
Z26Cfskxsu640QY0s/juZsHATWQrZGb5sJqHUf0U1CV54rhqlf6FuRzhmeqbl53/k/33z04yAnH
2HpzWJdXpgWGB1ovpT2qCNtSauHcePST7KjYAS0M+IdxLacLv8D8m59Pu1paZKnj3eOpx0SRopc
Ky0N4L8dUhL2kn48A/Icf54v5qMh1ZSTk39pYN3By3ANr1kYe8wGAjyg6Xiq801yQ/XcJh/Jsdy
LlEvEUAfpS4Mr5UPbB3kX9sM7UgKVPODlTdy+Sgxg9FH2uh2KYUJKZd3bxyA3vm91K+JgmmlPDD
3FIqJbIdc4yiUfqc78LVDW+dkdu0vEMj0BAv+6OtSx75M2P0FEq6MyhU2RPVLS3u8kIXz5WvrQJ
RqFMVqLlly0H/tvOdWyTVONjmMhNtpAWKQVzuyH5WsPRYY/pW1JoPu4PJMRhIYciE8GtwvvhuS+
/BlnHufWVv/ScVxY3JFTZWD+MNEDS0V+cTvwWONPKRzNH1gwzqPabldtmFHra+y5W5jSgo1KgH9
CuKEr19jmi0xzuomomA6Ez8PvDpQT9FHOQ==
X-Received: by 2002:a05:693c:638e:10b0:375:dbeb:b363 with SMTP id 5a478bee46e88-37686d341eemr6318709eec.28.1794500046419;
Thu, 12 Nov 2026 08:14:06 -0800 (PST)
X-Received: from [127.0.0.1] ([172.182.224.193])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-37925581683sm840634eec.11.2026.11.12.08.14.05
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 12 Nov 2026 08:14:05 -0800 (PST)
X-Fcc: Sent
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: Derrick Stolee <stolee@gmail.com>,
Kristofer Karlsson <krka@spotify.com>,
Kristofer Karlsson <krka@spotify.com>