pgsql: Micro-optimize appendStringInfo[VA]. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Micro-optimize appendStringInfo[VA].
Date
Msg-id E1wx68z-00000001NzU-3RSs@gemulon.postgresql.org
Whole thread
List pgsql-committers
Micro-optimize appendStringInfo[VA].

In the loop in appendStringInfo, avoid a useless assignment to
errno during the first (and usually only) iteration.  This
might make a noticeable difference depending on how efficiently
the platform deals with thread-local variables.

Try to make the compiler inline appendStringInfoVA into
appendStringInfo.

Instead of having appendStringInfoVA go through pvsnprintf, make
it call vsnprintf directly.  pvsnprintf adds little except an
int-versus-size_t impedance mismatch.  We do have to duplicate its
error handling for the nprinted < 0 case, but we don't need to
duplicate its check for MaxAllocSize overrun, because
enlargeStringInfo can handle that just as easily.  Also, its
insistence on adding one to nprinted is not needed here, since
enlargeStringInfo expects the number of data bytes to add.

In combination, these changes seem to about halve the penalty for
going through appendStringInfo rather than directly to snprintf.c.
This is enough to buy back the performance loss incurred in
formatting.c by the preceding three patches, and even a little more.
It should help other usages too.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/3451175.1786641871@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/38337ee639b1825597dee8cc02cc9c0aaa83feb1

Modified Files
--------------
src/common/stringinfo.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)


pgsql-committers by date:

Previous
From: Jeff Davis
Date:
Subject: pgsql: Ensure all pg_locale.h APIs work with collate_is_c.
Next
From: Jeff Davis
Date:
Subject: pgsql: hashtext: fix fragile code.