Re: Make tuple deformation faster - Mailing list pgsql-hackers

From James Hunter
Subject Re: Make tuple deformation faster
Date
Msg-id CAJVSvF7nWfK+4Kut2RTo8xm=nZN9gLMk6yUjkWMYH8D8P6NRcA@mail.gmail.com
Whole thread Raw
In response to Re: Make tuple deformation faster  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: Make tuple deformation faster
List pgsql-hackers
On Wed, Mar 5, 2025 at 10:40 AM Jeff Davis <pgsql@j-davis.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



pgsql-hackers by date:

Previous
From: Florents Tselai
Date:
Subject: Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part
Next
From: Robert Haas
Date:
Subject: Re: Add -k/--link option to pg_combinebackup