Re: [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chapman Flack <chap@anastigmatix.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>, Japin Li <japinli@hotmail.com>, pgsql-hackers@postgresql.org, mark.dilger@enterprisedb.com, andres@anarazel.de, pgsql-hackers@lists.postgresql.org
Date: 2021-10-28T17:46:49Z
Lists: pgsql-hackers
Chapman Flack <chap@anastigmatix.net> writes:
> On 10/27/21 18:18, Arjan van de Ven wrote:
>> +        /*
>> +         * Special case each of the possible base values  (8, 10, 16) to
>> avoid an
>> +         * expensive divide operation
>> +         * (the compiler will use a multiply, shift or boolean ops for this)
>> +         */

> Was 'boolean' the intended word there? To me it is distinct from 'bitwise'.

I think the comment is overly specific anyway.  We should just say
"division by a constant is faster than general-purpose division".
Only compiler geeks will care about the details, and they probably
know them already.

Personally, I failed to measure any speedup at all on pgbench, either
in the init phase or regular transactions; whatever difference there
may be is below the noise level.  However, I wrote a simple C function
with a tight loop around snprintf(), and that showed about a 2X
improvement, so there is some win here.

I went ahead and pushed it with a rewritten comment.

			regards, tom lane



Commits

  1. Speed up printing of integers in snprintf.c.