Re: Make tuple deformation faster
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Victor Yegorov <vyegorov@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, Matthias van de Meent <boekewurm+postgres@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-02T10:24:31Z
Lists: pgsql-hackers
Attachments
- v5-0001-Introduce-CompactAttribute-array-in-TupleDesc.patch (application/octet-stream) patch v5-0001
- v5-0002-Use-CompactAttribute-instead-of-FormData_pg_attri.patch (application/octet-stream) patch v5-0002
- v5-0003-Optimize-alignment-calculations-in-tuple-form-def.patch (application/octet-stream) patch v5-0003
- v5-0004-Remove-pg_attribute.attcacheoff-column.patch (application/octet-stream) patch v5-0004
- v5-0005-Speedup-tuple-deformation-with-additional-functio.patch (application/octet-stream) patch v5-0005
On Sat, 30 Nov 2024 at 02:54, Victor Yegorov <vyegorov@gmail.com> wrote: > I've been testing this patch for the last week, I have M3 and i7 based MBP around. Thanks for having a look at this and running the benchmarks. > Construct > sizeof(FormData_pg_attribute) * (src)->natts > is used in 7 places (in various forms), I thought it might be good > to use a macro here, say TupleArraySize(natts). I ended up adjusting the code here so that TupleDescSize() returns the full size and TupleDescAttrAddress() manually calculates the offset to start the FormData_pg_attribute array. That allows TupleDescFullSize() to be deleted. I changed how TupleDescCopy() works as it used to perform the memcpy in 2 parts. I've changed that to now perform a single memcpy() and reset the ->attrs field after the memcpy so that it correctly points to the address for its own TupleDesc rather than the one from the source. > In v4-0002-Introduce-CompactAttribute-array-in-TupleDesc.patch > > +#define COMPACT_ATTR_IS_PACKABLE(att) \ > +> ((att)->attlen == -1 && att->attispackable) > > Seems second att needs parenthesis around it. Adjusted. Thanks. > Although I haven't seen 30% speedup, I find this change very good to have. I think there's a bit more juice to squeeze out still. I started another thread for a much different approach to increasing the tuple deform performance over in [1]. The benchmarks I showed over there show the results with all the v4 patches on this thread plus that patch, and also another set of results from just the v4 patches from here. My Apple M2 very much likes the patch from the other thread. I don't have any decent Intel hardware to test on. I've attached a v5 set of patches, which I think addresses everything you mentioned. I've also shuffled the patches around a little to how I think they should be committed. Here's a summary: v5-0001: Adds the CompactAttribute struct, includes it in TupleDesc and adds all the code to populate it. Also includes a very small number of users of CompactAttribute. v5-0002: Adjusts dozens of locations to use CompactAttribute struct instead of the Form_pg_attribute struct. Lots of churn, but not complex changes. Separated out from v5-0001 so it's easier to see the important changes 0001 is making. v5-0003: Change CompactAttribute.attalign char field to attalignby to uint8 field to optimise alignment calculations and remove branching. v5-0004: Delete the now unused pg_attribute.attcacheoff column and Form_pg_attribute field. v5-0005: This is the patch from [1] rebased atop of this patch set. I'll pick up the discussion on that thread, but offering a rebased version here in case you'd like to try that one. I spent all day today reviewing and fixing up a few missing comments for the v5 patch series. I'm quite happy with these now. If nobody else wants to look or test, I plan on pushing these tomorrow (Tuesday UTC+13). If anyone wants me to delay so they can look, they better let me know soon. David [1] https://postgr.es/m/CAApHDvo9e0XG71WrefYaRv5n4xNPLK4k8LjD0mSR3c9KR2vi2Q@mail.gmail.com
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