Thread: pgsql: Optimize sifting down in binaryheap.

pgsql: Optimize sifting down in binaryheap.

From
Nathan Bossart
Date:
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(-)