pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@enterprisedb.com>
Subject: Re: Large writable variables
Date: Tue, 16 Oct 2018 13:11:45 -0700
Message-ID: <20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de> (raw)
In-Reply-To: <30245.1539699393@sss.pgh.pa.us>
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>

On 2018-10-16 10:16:33 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> 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

Attachments:

0001-Reorder-FmgrBuiltin-members-saving-25-in-size.patch (text/x-diff, 1.7K) download From 575a51d94fd4bef6914ba55b33ba96504f64d574 Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@anarazel.de> 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

view thread (51+ messages)  latest in thread

Message-ID: <20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de>
Permalink:  ../20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: andres@anarazel.de, tgl@sss.pgh.pa.us, thomas.munro@enterprisedb.com
  Subject: Re: Large writable variables
  In-Reply-To: <20181016201145.aa2dfeq54rhqzron@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox