From: | James Hunter <james(dot)hunter(dot)pg(at)gmail(dot)com> |
---|---|
To: | Jeff Davis <pgsql(at)j-davis(dot)com> |
Cc: | David Rowley <dgrowleyml(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Make tuple deformation faster |
Date: | 2025-03-05 19:33:02 |
Message-ID: | CAJVSvF7nWfK+4Kut2RTo8xm=nZN9gLMk6yUjkWMYH8D8P6NRcA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Mar 5, 2025 at 10:40 AM Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
>
> On Thu, 2025-03-06 at 01:07 +1300, David Rowley wrote:
> > I've attached the results. The 3990x with clang looks good, but the
> > rest are mostly slower.
>
> I am still curious why.
>
> If it's due to compiler misoptimization, is that kind of thing often
> misoptimized, or is there something we're doing in particular?
>
> Even if we don't have answers, it might be worth adding a brief comment
> that we empirically determined that booleans are faster than bitfields
> or flags. In the future, maybe compilers mostly get this right, and we
> want to change to bitfields.
I haven't run this sort of experiment in years, and CPUs continue to
improve -- but with a Boolean, the CPU can read from or write to that
Boolean directly, one instruction. A Boolean tends to be a byte, and
memory is byte-addressable.
For a bitfield, however, the CPU has to read from or write to the byte
that contains the bit, but then it also has to mask out the *other*
bits in that bitfield. This is a data dependency, so it stalls the CPU
pipeline.
So Booleans tend to be faster than bitfields, because they avoid a
pipeline stall.
James Hunter
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2025-03-05 19:34:52 | Re: Add -k/--link option to pg_combinebackup |
Previous Message | Florents Tselai | 2025-03-05 19:29:50 | Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part |