Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gCVh2-00016K-Sc for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Oct 2018 20:11:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gCVh1-000173-4R for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Oct 2018 20:11:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gCVh0-00016w-To for pgsql-hackers@lists.postgresql.org; Tue, 16 Oct 2018 20:11:50 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gCVgy-00020I-Vj for pgsql-hackers@postgresql.org; Tue, 16 Oct 2018 20:11:50 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A942920BE3; Tue, 16 Oct 2018 16:11:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 16 Oct 2018 16:11:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=SBYLgO8U+o8onpj5TQ5+1e8DW35 9oEHEkH/zId+aHiw=; b=q8xBJriNwscWCNMh60kLrpgeF88x/VH344vKf9WjoA1 5/HjGQZSFm83rtZIQB1cwNaUG89h/UKHOudW9dfVzdUr/BsrtkD2V7McaG+4UdEd qAOiZFy0ipbKs8s7JS0Ph+qbAMxHr4f+DYNfoJU+WD95cshb5KYLB3/xEoHQT242 CSInAmvcqk779+bav8DhkaKXofZFj6ZogLgiiAnfzCZmZYRkgO6WPsPbYfC9jAyY ZnFij1ZMGp7JKRPFuzX7QH9ZuNkpzTuMt/BU/4wS0CRy2pxKLP4Rl5jQW1lCkGdL 42OJrOuZ2CMtz879PapkpMywghFqEnaJ05xYCxWNspQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=SBYLgO 8U+o8onpj5TQ5+1e8DW359oEHEkH/zId+aHiw=; b=vaF56aCSSceJ9p/BHjw2HI r21OJwQTKOtLyPMYi+hXqlYB1GCljIBqBCxBEk5pJSHOJfr9kyeSdisO17NP83r1 NrbDKcY7yRAHQx4a1tgyc2zcj6iRZbXi9KIzlxWUZGA68tJW0gn3nr36J0SBgTcy 0g0glpPDReNsLojb9RwGoNloYvg6pCYLI0tk8g2of8iDOqdew0vpb7egwymciO+K Uq2BUr9s+G2JTLqU5U8RHAvRC2OsM79evG7Ft89isoORq5KBT8tkY2S09Ga50Tr5 0v+6xO3fFlYJ3/OK40DuE2sRbK61P2FZ/HkIJ1grk1D1BvEmR2WFX60RZxS4BcYw == X-ME-Sender: X-ME-Proxy: Received: from intern.anarazel.de (c-98-210-140-171.hsd1.ca.comcast.net [98.210.140.171]) by mail.messagingengine.com (Postfix) with ESMTPA id 8CD6D102EB; Tue, 16 Oct 2018 16:11:46 -0400 (EDT) Date: Tue, 16 Oct 2018 13:11:45 -0700 From: Andres Freund To: Tom Lane Cc: pgsql-hackers@postgresql.org, Thomas Munro Subject: Re: Large writable variables Message-ID: <20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de> References: <20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de> <31562.1539658872@sss.pgh.pa.us> <6813.1539669540@sss.pgh.pa.us> <20181016063317.xjfd2dnlhy6tg5gx@alap3.anarazel.de> <30245.1539699393@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="poaiyxh67qh66mar" Content-Disposition: inline In-Reply-To: <30245.1539699393@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --poaiyxh67qh66mar Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2018-10-16 10:16:33 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2018-10-16 01:59:00 -0400, Tom Lane wrote: > >> Also, I noticed that the biggest part of those structs are arrays of > >> FormatNode, which has been designed with complete lack of thought about > >> size or padding issues. We can very easily cut it in half on 64-bit > >> machines. > > > Heh, neat. I feel like we've paid very little attention to that in a > > myriad of places :( > > Most of the time, we probably *shouldn't* pay attention to it; logical > field ordering is worth a good deal IMO. Sure. But there's plenty structs which we allocate a bunch off, that are frequently accessed, where a lot of space is wasted to padding. I agree that we don't need to contort many structs, but there's plenty where we should. Often enough it's possible to reorder without making things make meaningfully less sense. > But in a case like this, > where there are large arrays of the things and it's not very painful > to avoid padding waste, it's worth the trouble. Attached is a patch that shrinks fmgr_builtins by 25%. That seems worthwhile, it's pretty frequently accessed, making it more dense is helpful. Unless somebody protests soon, I'm going to apply that... Greetings, Andres Freund --poaiyxh67qh66mar Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Reorder-FmgrBuiltin-members-saving-25-in-size.patch" From 575a51d94fd4bef6914ba55b33ba96504f64d574 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Tue, 16 Oct 2018 13:05:52 -0700 Subject: [PATCH] Reorder FmgrBuiltin members, saving 25% in size. That's worth it, as fmgr_builtins is frequently accessed, and as fmgr_builtins is one of the biggest constant variables in a backend. --- src/backend/utils/Gen_fmgrtab.pl | 2 +- src/include/utils/fmgrtab.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgrtab.pl index fa30436895b..ca282913552 100644 --- a/src/backend/utils/Gen_fmgrtab.pl +++ b/src/backend/utils/Gen_fmgrtab.pl @@ -230,7 +230,7 @@ my $fmgr_count = 0; foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) { print $tfh - " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} }"; + " { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, \"$s->{prosrc}\", $s->{prosrc} }"; $fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++; diff --git a/src/include/utils/fmgrtab.h b/src/include/utils/fmgrtab.h index d8317eb3eac..8d89d66777b 100644 --- a/src/include/utils/fmgrtab.h +++ b/src/include/utils/fmgrtab.h @@ -25,10 +25,10 @@ typedef struct { Oid foid; /* OID of the function */ - const char *funcName; /* C name of the function */ short nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable count */ bool strict; /* T if function is "strict" */ bool retset; /* T if function returns a set */ + const char * const funcName; /* C name of the function */ PGFunction func; /* pointer to compiled function */ } FmgrBuiltin; -- 2.18.0.rc2.dirty --poaiyxh67qh66mar--