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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: Arjan van de Ven <arjan(at)linux(dot)intel(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, mark(dot)dilger(at)enterprisedb(dot)com, andres(at)anarazel(dot)de, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint
Date: 2021-10-28 17:46:49
Message-ID: 541906.1635443209@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chapman Flack <chap(at)anastigmatix(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2021-10-28 18:02:14 Re: Delegating superuser tasks to new security roles (Was: Granting control of SUSET gucs to non-superusers)
Previous Message Bossart, Nathan 2021-10-28 16:37:49 Re: inefficient loop in StandbyReleaseLockList()