pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Optimize alignment calculations in tuple form/deform
Date: Fri, 20 Dec 2024 20:43:48 +0000
Message-ID: <E1tOjqd-000ZmL-H0@gemulon.postgresql.org> (raw)

Optimize alignment calculations in tuple form/deform

Here we convert CompactAttribute.attalign from a char, which is directly
derived from pg_attribute.attalign into a uint8, which stores the number
of bytes to align the column's value by in the tuple.

This allows tuple deformation and tuple size calculations to move away
from using the inefficient att_align_nominal() macro, which manually
checks each TYPALIGN_* char to translate that into the alignment bytes
for the given type.  Effectively, this commit changes those to TYPEALIGN
calls, which are branchless and only perform some simple arithmetic with
some bit-twiddling.

The removed branches were often mispredicted by CPUs, especially so in
real-world tables which often contain a mishmash of different types
with different alignment requirements.

Author: David Rowley
Reviewed-by: Andres Freund, Victor Yegorov
Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/db448ce5ad36a2754e4e75900b180260143aacf8

Modified Files
--------------
contrib/amcheck/verify_heapam.c        |  6 ++--
contrib/pageinspect/heapfuncs.c        |  6 ++--
src/backend/access/brin/brin_tuple.c   | 10 ++++---
src/backend/access/common/attmap.c     |  6 ++--
src/backend/access/common/heaptuple.c  | 52 ++++++++++++++++------------------
src/backend/access/common/indextuple.c | 22 +++++++-------
src/backend/access/common/tupdesc.c    | 20 ++++++++++++-
src/backend/executor/execExprInterp.c  |  2 +-
src/backend/executor/execTuples.c      | 20 ++++++-------
src/backend/jit/llvm/llvmjit_deform.c  | 17 +----------
src/include/access/tupdesc.h           |  2 +-
src/include/access/tupmacs.h           | 27 ++++++++++++++++++
12 files changed, 110 insertions(+), 80 deletions(-)



Message-ID: <E1tOjqd-000ZmL-H0@gemulon.postgresql.org>
Permalink:  ../E1tOjqd-000ZmL-H0@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tOjqd-000ZmL-H0@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Optimize alignment calculations in tuple form/deform
  In-Reply-To: <E1tOjqd-000ZmL-H0@gemulon.postgresql.org>

* 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