Re: define pg_structiszero(addr, s, r)
Ranier Vilela <ranier.vf@gmail.com>
From: Ranier Vilela <ranier.vf@gmail.com>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>,
Michael Paquier <michael@paquier.xyz>, Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, Heikki Linnakangas <hlinnaka@iki.fi>, pgsql-hackers@lists.postgresql.org
Date: 2024-11-04T17:38:54Z
Lists: pgsql-hackers
Hi. Em seg., 4 de nov. de 2024 às 14:18, Bertrand Drouvot < bertranddrouvot.pg@gmail.com> escreveu: > 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 > - adding an Assert for ptr != 0 > - re-introduce the function call in PageIsVerifiedExtended() > - propose a commit message > I think we can add a small optimization to this last patch [1]. The variable *aligned_end* is only needed in the second loop (for). So, only before the for loop do we actually declare it. Result before this change: check zeros using BERTRAND 1 0.000031s Result after this change: check zeros using BERTRAND 1 0.000018s + const unsigned char *aligned_end; + /* Multiple bytes comparison(s) at once */ + aligned_end = (const unsigned char *) ((uintptr_t) end & (~(sizeof(size_t) - 1))); + for (; p < aligned_end; p += sizeof(size_t)) best regards, Ranier Vilela [1] https://godbolt.org/z/fvdzjbnc7
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