Re: Make tuple deformation faster

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Make tuple deformation faster
Date: 2024-09-03 05:05:55
Message-ID: CAApHDvpHmUuFY9rtRw6oiG7OTM-o+BnODg1m-EynKGbbhSsMzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 6 Aug 2024 at 13:11, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> I'll put this up for the CF bot to run with for a bit as the patch has
> needed a rebase since I pushed the v1-0001 patch.

I've been doing more work on this patch set as I'd been concerned
there wasn't any validation to ensure the TupleDesc's
FormData_pg_attribute and the CompactAttribute are kept in sync when
the TupleDesc is altered in various places around the codebase. To
make this more robust, in USE_ASSERT_CHECKING builds, I made it so the
TupleDescCompactAttr() macro is turned into an inline function with an
Assert to validate the stored CompactAttribute vs one freshly
populated from the FormData_pg_attribute. Doing this caused me to find
a missed call to populate_compact_attribute(), so was worth the
effort. There's no apparent performance difference when running all
the tests with and without this extra checking.

I also spent time doing performance tests using 3 different machines.
I didn't document the previous performance tests, but I expect I ran
them on my AMD 7945hx laptop. On testing again today, I used that
Zen4 laptop plus an AMD 3990x (Zen2) and a 10-core Apple M2. I found
that it was only the 7945hx laptop that was showing any decent gains
from this patch :(. After thinking for a bit, I decided to expand the
CompactAttribute.attflags where I'd been bit packing in 5 boolean
fields from pg_attribute and expand those into bool fields. This made
the performance much better. The 0005 contains this change
independently.

Please see the attached "patches-0001-0005_results.png". This shows
the test query running 25% faster on the 7945hx laptop with gcc. The
least gains were from the Apple M2 at about a 9-10% increase.

The "patches-0001-0004_results.png" shows the results with the smaller
bit-packed CompactAttriubute struct. You can see that without the 0005
patch, there are some performance regressions, so I propose including
0005 which widens CompactAttribute from 8 bytes to 16 bytes.

David

Attachment Content-Type Size
deform_test.sh.txt text/plain 1.1 KB
patches-0001-0005_results.png image/png 126.5 KB
patches-0001-0004_results.png image/png 117.6 KB
v3-0001-Move-TupleDesc.attrs-out-of-line.patch application/octet-stream 6.4 KB
v3-0002-Introduce-CompactAttribute-array-in-TupleDesc.patch application/octet-stream 62.9 KB
v3-0003-Optimize-alignment-calculations-in-tuple-form-def.patch application/octet-stream 18.3 KB
v3-0004-Remove-pg_attribute.attcacheoff-column.patch application/octet-stream 11.5 KB
v3-0005-Try-a-larger-CompactAttribute-struct-without-flag.patch application/octet-stream 3.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-09-03 05:13:14 Re: DOCS - pg_replication_slot . Fix the 'inactive_since' description
Previous Message Bertrand Drouvot 2024-09-03 05:00:54 Re: Add callback in pgstats for backend initialization