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

2021-10-28 Thread Tom Lane
Andres Freund writes: > Imo the code now is a bit odd, because we first switch (type) setting base, > and then separately have branches for the different bases. It'd be hard to merge, I think, given that the cases in the switch don't line up one-for-one with the different bases. You could probab

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

2021-10-28 Thread Andres Freund
Hi, On 2021-10-28 13:46:49 -0400, Tom Lane wrote: > 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 snpri

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

2021-10-28 Thread Tom Lane
Chapman Flack 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) >> +

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

2021-10-27 Thread Chapman Flack
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

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

2021-10-27 Thread Arjan van de Ven
On 10/26/2021 6:39 PM, Tom Lane wrote: Japin Li writes: Why do we need likely() for base=10, however, base=16 and base=8 don't need? Yeah, I was a little unconvinced about that too. I concur with writing it as an if/else chain instead of a switch, but I'm not sure that likely() adds anything

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

2021-10-26 Thread Tom Lane
Japin Li writes: > Why do we need likely() for base=10, however, base=16 and base=8 don't need? Yeah, I was a little unconvinced about that too. I concur with writing it as an if/else chain instead of a switch, but I'm not sure that likely() adds anything to that. regard

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

2021-10-26 Thread Japin Li
On Wed, 27 Oct 2021 at 04:58, Arjan van de Ven wrote: > [PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint > > fmtint() turns an integer into a string for a given base, and to do this > it does a divide/modulo operation iteratively. > The only possible ba

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

2021-10-26 Thread Arjan van de Ven
[PATCH v2] src/port/snprintf.c: Optimize the common base=10 case in fmtint fmtint() turns an integer into a string for a given base, and to do this it does a divide/modulo operation iteratively. The only possible base values are 8, 10 and 16 On just about any CPU, divides are a pretty expensive