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

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reduce branches in heapgetpage()'s per-tuple loop
Date: 2024-04-07 07:29:18
Message-ID: E1rtMxq-000wGZ-6c@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <johncnaylorls(at)gmail(dot)com>
Reviewed-by: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
Tested-by: Quan Zongliang <quanzongliang(at)yeah(dot)net>
Discussion: https://postgr.es/m/20230716015656.xjvemfbp5fysjiea@awork3.anarazel.de
Discussion: https://postgr.es/m/2ef7ff1b-3d18-2283-61b1-bbd25fc6c7ce@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(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2024-04-07 09:20:52 pgsql: Avoid needless large memcpys in libpq socket writing
Previous Message Nathan Bossart 2024-04-07 04:00:52 pgsql: Optimize visibilitymap_count() with AVX-512 instructions.