🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3083

[PATCH v2] commit: remove padding from struct commit

#3083
From: "Kristofer Karlsson via GitGitGa...
Date: Fri, 13 Nov 2026 13:30
157 lines
15982 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.

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>
---
    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".
    
    Changes since v1:
    
     * Document that "object" must be the first member, and that the order
       of the other members is partly chosen for a compact memory layout
       rather than reflecting their importance (Junio).
    
     * Add comments describing "index" and "date" (Junio).
    
    A regression check for the padding (unit test or a scoped -Wpadded) and
    a build-time assertion that "object" comes first are discussed in the v1
    thread; I will send those separately.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2309%2Fspkrka%2Fcommit-index-hole-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2309/spkrka/commit-index-hole-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2309

Range-diff vs v1:

 1:  20de8db00d ! 1:  f8f0dbcf46 commit: remove padding from struct commit
     @@ Commit message
          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):
      
     @@ Commit message
      
       ## commit.h ##
      @@ commit.h: 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.
     ++ *
     ++ * The order of the members is partly chosen to keep the memory layout
     ++ * compact (avoiding alignment padding), and does not necessarily
     ++ * reflect their importance or grouping.
        */
       struct commit {
     ++	/*
     ++	 * Must be the first member, so that a "struct object *" can be
     ++	 * cast to a "struct commit *".
     ++	 */
       	struct object object;
     ++
     ++	/*
     ++	 * Index into the commit-slab arrays: unique per in-core commit,
     ++	 * and only meaningful within the current process.
     ++	 */
      +	unsigned int index;
     ++
     ++	/*
     ++	 * The committer date taken from the commit object, without any
     ++	 * adjustment.
     ++	 */
       	timestamp_t date;
     ++
       	struct commit_list *parents;
       
     + 	/*
      @@ commit.h: struct commit {
       	 * or get_commit_tree_oid().
       	 */


 commit.h | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/commit.h b/commit.h
index 1061ed791b..d43cb1e46d 100644
--- a/commit.h
+++ b/commit.h
@@ -23,10 +23,30 @@ 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.
+ *
+ * The order of the members is partly chosen to keep the memory layout
+ * compact (avoiding alignment padding), and does not necessarily
+ * reflect their importance or grouping.
  */
 struct commit {
+	/*
+	 * Must be the first member, so that a "struct object *" can be
+	 * cast to a "struct commit *".
+	 */
 	struct object object;
+
+	/*
+	 * Index into the commit-slab arrays: unique per in-core commit,
+	 * and only meaningful within the current process.
+	 */
+	unsigned int index;
+
+	/*
+	 * The committer date taken from the commit object, without any
+	 * adjustment.
+	 */
 	timestamp_t date;
+
 	struct commit_list *parents;
 
 	/*
@@ -35,7 +55,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.v2.git.1794576606249.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-75376-linux-kernel-git=dewy.ru
References: <pull.2309.git.1794500044740.gitgitgadget@gmail.com>

Show 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-75376-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Kristofer Karlsson via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v2] commit: remove padding from struct commit
Date: Fri, 13 Nov 2026 13:30:06 +0000
Organization: Usenet Network
Message-ID: <pull.2309.v2.git.1794576606249.gitgitgadget@gmail.com>
References: <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="1428990"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:26CInV+/jG7ex3dB744koHMZLm8= sha256:VMydZL03DIHPAK0VDFDAMS+DHIHEJs0b1u66LYNqoRs=
	sha1:fkQ43zJgu3J///U+5Hia5ZTXxQI= sha256:6oXo98WjAdHaeAl6wH8uajTyJ4qoBlQj3XF6eC8Fjlo=
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 CC918114650; Fri, 13 Nov 2026 23:14:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.049
X-Spam-Status: No, score=-2.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FORGED_GMAIL_RCVD=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 1TLzzpOpZB81;
	Fri, 13 Nov 2026 23:14:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-75376-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 38B4B114589; Fri, 13 Nov 2026 23:14:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 32B8AE8AB6; Fri, 13 Nov 2026 13:35:01 +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=1794576610;
	b=pAf+XvkUdqY2Lj+Hh3n3ONho5cu6BBQF+Lv4ph1D4Zw3c2QPyjGmCub7fKrj7T2jH2Eb
	 /T8DgVcxEA7D1a3EABOjcf7N2Z4bYMllAG7SByuc/ioOs4Cm7RvTMC53My9bkomhbGIhN
	 5lyeMQ4I32a1sFNwrduYlvZtAoBzJ6ygiNci8PCAmvUeLDA+3L+1uWlXR92rXjxpw7PnW
	 dfwqOBVB2sE3P54bddqHfRuatFgVQFsbef9oIq6MdOPfDBma2Ouxjvs/mrE4uW0rEPFrf
	 OIf7I5f4ml71c9XKbNOIiCOn5aTNgBmvQguWTDQNyY/bFv8z7059P9tVbONPB8OAZzQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794576610;
	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:In-Reply-To:References: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=bR9NMNCBf4ATs5CLmd99M6HNx7u+I77aVIH25ccvLcs=;
	b=nWZqTZdirXfDZrylm9CFfHiBDrjRUgyUKK8go/GWx1oyulOn2tE61DQGOO3mA4hfr7M6
	 V+n2bRnzob4vVOP5OKmGbNSTphd6yvDIq072Z+Zat5WpiTRTj+zMuKpiCsjvRkX2q+q4y
	 o2KsKHUnZlokij7/M+Bv0EJSwepM+ZviBSEHUEiPgy2SN0thWz04wwSAKcMo18W2UMgVK
	 XdS2CzAHPd1oyhtTSPZcs2ppP+I0bFmMzeOaxLb4ti5JAizMaYxqAwalNHhNQj9q2Zf01
	 lnY9wEN/PyIixOR4bTMQWAaqaL10t44DpG5a8eA3NIkxHAovhre/Id7KECvPkB9cIMg==
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=tPDJtpdp;
	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 C33C9606D488;
	Fri, 13 Nov 2026 13:30:10 +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=tPDJtpdp
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794576610;
	b=TM3hIANcE3TxW+5lpjleT11LIdZRJhgsmEwCgJ8RPut4ICQmg70zZ2BJ9Wnw/xW1VtQf
	 UYuZjJg31yLMCCejkoWQoLrG8WXPxxrw8AJrfHBIlrRUQ76w8t/qlhccPARdkspj3rdU0
	 onH9/6kyfQu6xAe54MhoOgTocP5iY+qKQGZPVrMUZBtl7DDY6q4f9YN+pDvdg+s6MopXV
	 /bPi/ru4QxToIuzkJ/vMnh3UdifidaEJ+t2MW6v0nMBDLxmwZaMDchDdWvZGCw21xbYrc
	 hPlj+Mv/euoMpz7RzYj/5LlLUkp9IeuZq7WVSaWX12O975/K9e08jGRcPJzjtXp0Xvw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794576610;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To:
	 References:From:Date:Subject:Fcc:Content-Type:
	 Content-Transfer-Encoding:MIME-Version:To:Cc;
	bh=bR9NMNCBf4ATs5CLmd99M6HNx7u+I77aVIH25ccvLcs=;
	b=SqdrKWWh3LVNo9N4YsyZcwDKMQoKhXjF1lihjiP4rhxx0kDvNa1NWvLWpX9qsP1fTFN2
	 G2KqUOyUnGqzuvBKyyEla/dW2wkXKYSQlKHjhC/Xbf7CwSFApKDrVaujZAQyG2w3Z3hzW
	 Hm8fzPixi566JeEKQnT/jvs6FeapoAr0aY+/sIG0eAzC6NLvqWjNJEzBnYkBbKjJUwqz5
	 o1q1oUQp1YonNXSag/dlWvKguIH4Luy7+WLNXxsfqYhFdmTclbLQltFEbQVOuJ2G2ASvL
	 CL0WIWK5GLP/9+Pahod3SxNpAyCUdpDLbfN4f52l900ZcU7EVhw4/4HtBovKmjRFdQw==
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=tPDJtpdp;
	arc=none smtp.remote-ip=209.85.219.43
X-Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43])
	(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 91B7F606ABAE
	for <git@vger.kernel.org>; Fri, 13 Nov 2026 13:30:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 91B7F606ABAE
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-qv1-f43.google.com with SMTP id 6a1803df08f44-91e8a05ec5aso21885236d6.1
        for <git@vger.kernel.org>; Fri, 13 Nov 2026 05:30:09 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1794576608; x=1795181408; darn=vger.kernel.org;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:references:in-reply-to:message-id:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=bR9NMNCBf4ATs5CLmd99M6HNx7u+I77aVIH25ccvLcs=;
        b=tPDJtpdpZ89TvoeA5I094EGGr+r8NtmjVmjAHm4Hz5IAndhz99BltlzCltPa8nOnln
         O5IE6egE4VSCmdtIgzOmw2NugozjT9yks2H/dSdchKEAf1AN1qOyvujJI0Co2sTdALRr
         NhOhGnJ6OWZGhyi6+I7Eo9hH/Bg0O/6BkuFFohhR51GZk+kwpsxrpIEmPlw8EmaR2wLa
         YVCJwZk+RYKdX4XdYUmxfGOkyWHyVd4DOPbemE5n44elmwkWwm/KJCa2QIrnga7gvsDX
         OnniDRydRbcNlqYK0wU/qDuOzu6YmKgRCASz44MhT2KhnxZwHETJ99u0XaAuvQq/JRfo
         omgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794576608; x=1795181408;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:references:in-reply-to:message-id:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=bR9NMNCBf4ATs5CLmd99M6HNx7u+I77aVIH25ccvLcs=;
        b=am5MpREHfFqVHdleLPMwpeh/+xKomjei/+2AuAC6d61npt1PK4+4JffGptECmc2lUe
         UezoEERCdL2AqDY+tL8e8sh0uq7w2/Q1fqcN8MUfpJuo2obKG18TDA3S1WtHcM02Vs3l
         fp+KG03SSiJicHoLsJZq1zhv+jLxMuoDxWI40HsJM/4yVMJLnMvWFeSbjFZYxTZ6ENcr
         Y7lWr+IptNoBQaWS+qg+3DDuXcxmU1UzW0BzH+61ldR+LtbwpNO/8y64D2JcVP1I6lz1
         LF1ZYBkYKWcBNfnpVhFOxQn2jawesGyC56Te0lNt6Yy9yJ0tDlgf/nCyI7Wb7lXvG84j
         xiWQ==
X-Gm-Message-State: APuU4Z+wGwhyGwJxheCqPIZHAk6idSr8adCUV2VJP/pk5AkjCdinjRBM
	kTLmUaNGS1aHafkG4mQhzQK/1eoOU+OyU9qb7CfwTMrxpkhi81HilDVBiuI3Pg==
X-Gm-Gg: AYBFou0eAjiofEtXnZRzOg15JSLCSb4B3asOwiR19QOWGXlRHzHsddw1OdCZUUmE9Tj
	knlrWolvyrmP9gNBx1XJO5UAKk6s/PdpMKYh/qFAQk0kuhXJ3GEFhKFUe4OfUwWA4LfQvxQ+5gz
	x2flRKM6dsuFAh0uWDiYbwKnh8irjlaYcBvOcdAMQijnS80uxIiSbo9kPe+gpp7c+obWuED0Tcz
	E6FB/ecug16puhlzbmZ7fHc8KnqqFmLmbjt0gJ5qvfyzH184iLA18XLgpCRZ+40txMQB9a9Iu0E
	lv8Vl3oHcXo31I6GdaUzK8Gom8Zbf5r/YMfoByRlD9wXuB8Z7Tevqm7X7YwyrfIqxYTDQrLjkUm
	Uqps2X/Ot8uSGzH1RP2hVzAPiBxOMcjBE0jokRS4sDSB41mjuzkGmtf6KdZxPPSjiTkUsMn1tm3
	5ipD/DWCOi5XRfXzkvYX4/+sxSzm8os+HGnBX+GT7DyZFGzp/5VcJtqqbabNTAqYTHc3yMbZRax
	rkg2q/04Rd6ITPBtrYr8a8VCBJsbw7rp5cNx0duQzyc2plzs6zT57EzOa67pBRtdsvOrBVfdjtY
	/l7fQ0rDdJBROVvDZBMrWiL2+YM=
X-Received: by 2002:a0c:f099:0:b0:91f:3103:cb59 with SMTP id 6a1803df08f44-91f3103ce56mr130836d6.5.1794576608219;
        Fri, 13 Nov 2026 05:30:08 -0800 (PST)
X-Received: from [127.0.0.1] ([4.236.94.0])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91f23db0f58sm20189886d6.39.2026.11.13.05.30.06
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Nov 2026 05:30:06 -0800 (PST)
X-In-Reply-To: <pull.2309.git.1794500044740.gitgitgadget@gmail.com>
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>