Re: define pg_structiszero(addr, s, r)
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: David Rowley <dgrowleyml@gmail.com>, Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, Heikki Linnakangas <hlinnaka@iki.fi>, pgsql-hackers@lists.postgresql.org
Date: 2024-11-05T05:59:46Z
Lists: pgsql-hackers
Attachments
- v2-0001-Optimize-pg_memory_is_all_zeros.patch (text/x-diff)
Hi, On Tue, Nov 05, 2024 at 01:31:58PM +0900, Michael Paquier wrote: > On Mon, Nov 04, 2024 at 05:17:54PM +0000, Bertrand Drouvot wrote: > > Hi, > > > > On Tue, Nov 05, 2024 at 12:24:48AM +1300, David Rowley wrote: > > > On Sat, 2 Nov 2024 at 01:50, Bertrand Drouvot > > > <bertranddrouvot.pg@gmail.com> wrote: > > > > > > > > On Fri, Nov 01, 2024 at 09:47:05PM +1300, David Rowley wrote: > > > > > I've attached what I thought a more optimal version might look like in > > > > > case anyone thinks making it better is a good idea. > > > > > > > > > > > > > Thanks for the proposal! > > > > > > > > I like the idea, I think that's worth to add a few comments, something like: > > > > > > I'm happy if you want to pick this up and continue working on it. > > > > Sure, please find attached v1, the changes are: > > > > - switch from "const char" to "const unsigned char" (could have been done in the > > current version of pg_memory_is_all_zeros() though) > > - added some comments > > + * The test is divided into three phases for efficiency: > + * - Initial alignment (byte per byte comparison) > + * - Multiple bytes comparison at once > + * - Remaining bytes (byte per byte comparison) > > It does not look like this insists enough on the alignment part of the > optization? A MAXALIGN'd size would use only size_t comparisons, and > a pointer aligned would do no byte comparisons. I'm not sure to get this one. Is it more clear in the code comments that we can start multiple bytes comparison once p is aligned? > > - adding an Assert for ptr != 0 > > I'm not sure that the Assert() addition is a good idea. That could > get hot very easily depending on the caller, even if for assert > builds we don't care much about the performance, that could lead to > some paths being a lot slower. Yeah, agree, removed in v2 attached. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Commits
-
Use pg_memory_is_all_zeros() in PageIsVerifiedExtended()
- 03a42c9652f8 18.0 landed
-
Optimize pg_memory_is_all_zeros() in memutils.h
- 5be1dabd2ae0 18.0 landed
-
Remove use of pg_memory_is_all_zeros() in bufpage.c
- e819bbb7c82a 18.0 landed
-
Add pg_memory_is_all_zeros() in memutils.h
- 07e9e28b56db 18.0 landed