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

From Tom Lane
Subject Re: [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint
Date
Msg-id 541906.1635443209@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint  (Chapman Flack <chap@anastigmatix.net>)
Responses Re: [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint  (Andres Freund <andres@anarazel.de>)
List 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



pgsql-hackers by date:

Previous
From: "Bossart, Nathan"
Date:
Subject: Re: inefficient loop in StandbyReleaseLockList()
Next
From: Mark Dilger
Date:
Subject: Re: Delegating superuser tasks to new security roles (Was: Granting control of SUSET gucs to non-superusers)