Re: pgsql: Reduce branches in heapgetpage()'s per-tuple loop

2024-04-07 Thread Andres Freund
Hi,

On 2024-04-07 09:14:57 -0400, Melanie Plageman wrote:
> On Sun, Apr 7, 2024 at 3:29 AM Andres Freund  wrote:
> >
> > Reduce branches in heapgetpage()'s per-tuple loop
> >
> > Until now, heapgetpage()'s loop over all tuples performed some conditional
> > checks for each tuple, even though condition did not change across the loop.
> 
> I haven't reviewed exactly what this does, but heapgetpage() was
> removed (or split into two functions, rather) in 44086b097537, so I
> find the naming of this function, or, at least the comments, commit
> message and description a bit confusing.

Oops. That name was so ingrained in my head that despite looking over these
lines quite a few times, I couldn't spot that.

Will send an update to the thread.

Greetings,

Andres Freund




Re: pgsql: Reduce branches in heapgetpage()'s per-tuple loop

2024-04-07 Thread Melanie Plageman
On Sun, Apr 7, 2024 at 3:29 AM Andres Freund  wrote:
>
> Reduce branches in heapgetpage()'s per-tuple loop
>
> Until now, heapgetpage()'s loop over all tuples performed some conditional
> checks for each tuple, even though condition did not change across the loop.

I haven't reviewed exactly what this does, but heapgetpage() was
removed (or split into two functions, rather) in 44086b097537, so I
find the naming of this function, or, at least the comments, commit
message and description a bit confusing.

- Melanie




pgsql: Reduce branches in heapgetpage()'s per-tuple loop

2024-04-07 Thread Andres Freund
Reduce branches in heapgetpage()'s per-tuple loop

Until now, heapgetpage()'s loop over all tuples performed some conditional
checks for each tuple, even though condition did not change across the loop.

This commit fixes that by moving the loop into an inline function. By calling
it with different constant arguments, the compiler can generate an optimized
loop for the different conditions, at the price of two per-page checks.

For cases of all-visible tables and an isolation level other than
serializable, speedups of up to 25% have been measured.

Reviewed-by: John Naylor 
Reviewed-by: Zhang Mingli 
Tested-by: Quan Zongliang 
Discussion: 
https://postgr.es/m/20230716015656.xjvemfbp5fysj...@awork3.anarazel.de
Discussion: https://postgr.es/m/2ef7ff1b-3d18-2283-61b1-bbd25fc6c...@yeah.net

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a97bbe1f1df9eba0b18207c321c67de80b33db16

Modified Files
--
src/backend/access/heap/heapam.c | 102 ---
1 file changed, 74 insertions(+), 28 deletions(-)