pgsql: Optimize sifting down in binaryheap.

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Optimize sifting down in binaryheap.
Date: 2024-10-30 16:29:12
Message-ID: E1t6BZJ-003AmX-1k@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Optimize sifting down in binaryheap.

Presently, each iteration of the loop in sift_down() will perform
3 comparisons if both children are larger than the parent node (2
for comparing each child to the parent node, and a third to compare
the children to each other). By first comparing the children to
each other and then comparing the larger child to the parent node,
we can accomplish the same thing with just 2 comparisons (while
also not affecting the number of comparisons in any other case).

Author: ChangAo Chen
Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/tencent_0142D8DA90940B9930BCC08348BBD6D0BB07%40qq.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/849110dd3eec3e21c358e24f11c6d501d05eee72

Modified Files
--------------
src/common/binaryheap.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2024-10-30 17:44:04 pgsql: Clarify nbtree array exhaustion comments.
Previous Message Tom Lane 2024-10-30 15:42:41 pgsql: Stabilize jsonb_path_query test case.