Re: WIP: Make timestamptz_out less slow. - Mailing list pgsql-hackers

From Andres Freund
Subject Re: WIP: Make timestamptz_out less slow.
Date
Msg-id 20150728071029.GB5000@alap3.anarazel.de
Whole thread Raw
In response to Re: WIP: Make timestamptz_out less slow.  (David Rowley <david.rowley@2ndquadrant.com>)
Responses Re: WIP: Make timestamptz_out less slow.  (David Rowley <david.rowley@2ndquadrant.com>)
List pgsql-hackers
On 2015-07-28 10:59:15 +1200, David Rowley wrote:
> It won't be quite as fast as what you've written, but I think it will be
> much neater and more likely to be used in other places if we invent a
> function like pg_ltoa() which returns a pointer to the new end of string.
> 
> Also if we're specifying padding with zeros then we can skip the reverse
> part that's in pg_ltoa(), (normally needed since the numeric string is
> build in reverse)
> 
> The code could then be written as:
> 
> str = pg_int2str_pad(str, year, 4);
> *str++ = '-';
> str = pg_int2str_pad(str, tm->tm_mon, 2);
> *str++ = '-';
> str = pg_int2str_pad(str, tm->tm_mday, 2);
> 
> etc
> 
> I've used this method before and found it to be about 10 times faster than
> snprintf(), but I was reversing the string, so quite likely it be more than
> 10 times.

Yes, that might be worthwhile to try. Certainly would look less
ugly. Willing to give it a try?

> I'm interested to see how much you're really gaining by manually unrolling
> the part that builds the fractional part of the second.

It seems to help a fair amount, but this really was more a quick POC
than something serious. My theory why it helps is that each loop
iteration is independent of the previous one and thus can take full
advantage of the pipeline.

Regards,

Andres



pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: Autonomous Transaction is back
Next
From: Amit Langote
Date:
Subject: Typo in a comment in set_foreignscan_references