Re: Make tuple deformation faster
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Matthias van de Meent <boekewurm+postgres@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-09-03T05:05:55Z
Lists: pgsql-hackers
Attachments
- deform_test.sh.txt (text/plain)
- patches-0001-0005_results.png (image/png)
- patches-0001-0004_results.png (image/png)
- v3-0001-Move-TupleDesc.attrs-out-of-line.patch (application/octet-stream) patch v3-0001
- v3-0002-Introduce-CompactAttribute-array-in-TupleDesc.patch (application/octet-stream) patch v3-0002
- v3-0003-Optimize-alignment-calculations-in-tuple-form-def.patch (application/octet-stream) patch v3-0003
- v3-0004-Remove-pg_attribute.attcacheoff-column.patch (application/octet-stream) patch v3-0004
- v3-0005-Try-a-larger-CompactAttribute-struct-without-flag.patch (application/octet-stream) patch v3-0005
On Tue, 6 Aug 2024 at 13:11, David Rowley <dgrowleyml@gmail.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
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix possible Assert failure in verify_compact_attribute()
- 33b06a20016d 18.0 landed
-
Speedup tuple deformation with additional function inlining
- 58a359e585d0 18.0 landed
-
Fix race condition in TupleDescCompactAttr assert code
- 6f3820f37aba 18.0 landed
-
Optimize alignment calculations in tuple form/deform
- db448ce5ad36 18.0 landed
-
Remove pg_attribute.attcacheoff column
- 02a8d0c45253 18.0 landed
-
Introduce CompactAttribute array in TupleDesc, take 2
- 5983a4cffc31 18.0 landed
-
Introduce CompactAttribute array in TupleDesc
- d28dff3f6cd6 18.0 landed
-
Use TupleDescAttr macro consistently
- 65b71dec2d57 18.0 landed