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 <[email protected]>
Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

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

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

Reply via email to