From f4b88d3533008c2d7a23f6b907d4d1adac6dad02 Mon Sep 17 00:00:00 2001 From: Andy Fan Date: Wed, 11 Sep 2024 12:25:52 +0800 Subject: [PATCH v20260912 3/4] add unlikely hint for enlargeStringInfo. enlargeStringInfo has a noticeable ratio in perf peport with a "select * from pg_class" workload). So add a unlikely hint in enlargeStringinfo to avoid some overhead. --- src/common/stringinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/stringinfo.c b/src/common/stringinfo.c index ae39540e468..a725ef132d7 100644 --- a/src/common/stringinfo.c +++ b/src/common/stringinfo.c @@ -345,7 +345,7 @@ enlargeStringInfo(StringInfo str, int needed) * Guard against out-of-range "needed" values. Without this, we can get * an overflow or infinite loop in the following. */ - if (needed < 0) /* should not happen */ + if (unlikely(needed < 0)) /* should not happen */ { #ifndef FRONTEND elog(ERROR, "invalid string enlargement request size: %d", needed); @@ -354,7 +354,7 @@ enlargeStringInfo(StringInfo str, int needed) exit(EXIT_FAILURE); #endif } - if (((Size) needed) >= (MaxAllocSize - (Size) str->len)) + if (unlikely(((Size) needed) >= (MaxAllocSize - (Size) str->len))) { #ifndef FRONTEND ereport(ERROR, -- 2.43.0