Re: WIP: Make timestamptz_out less slow.

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: WIP: Make timestamptz_out less slow.
Date: 2015-09-03 13:04:01
Message-ID: CAKJS1f9sAx8RaK3SXm9okN72zXwMF2ux_Bpp0V+BHQQC4yk6zw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 3 September 2015 at 22:17, Andres Freund <andres(at)anarazel(dot)de> wrote:

> On 2015-09-03 16:28:40 +1200, David Rowley wrote:
> > I experimented with finding the fastest way to convert an int to a string
> > at the weekend, I did happen to be testing with int64's but likely int32
> > will be the same.
> >
> > This is the time taken to convert 30 into "30" 2 billion times.
> >
> > The closest implementation I'm using in the patch is pg_int64tostr() one.
> > The pg_int64tostr_memcpy() only performs better with bigger numbers /
> > longer strings.
> >
> > david(at)ubuntu:~/C$ gcc5.2 tostring.c -o tostring -O2
> > david(at)ubuntu:~/C$ ./tostring
> > pg_int64tostr_memcpy in 13.653252 seconds
> > pg_int64tostr in 2.042616 seconds
> > pg_int64tostr_new in 2.056688 seconds
> > pg_lltoa in 13.604653 seconds
> >
> > david(at)ubuntu:~/C$ clang tostring.c -o tostring_clang -O2
> > david(at)ubuntu:~/C$ ./tostring_clang
> > pg_int64tostr_memcpy in 0.000004 seconds
> > pg_int64tostr in 2.063335 seconds
> > pg_int64tostr_new in 2.102068 seconds
> > pg_lltoa in 3.424630 seconds
>
> Are you sure this isn't an optimization artifact where the actual work
> is optimized away? Doing 2 billion conversions in 2s kinda implies that
> the string conversion is done in ~4 cycles. That seems unrealistically
> fast, even for a pipelined cpu.
>

I think you're right.
If I change the NUM_TO_STRING in my tostring.c to
#define NUM_TO_PRINT i%100

I just wanted a way to keep the strings 2 digits long, so that it matches
what will happen when building timestamps.

It looks a bit different, but it's still a bit faster than pg_lltoa()

david(at)ubuntu:~/C$ ./tostring
pg_int64tostr_memcpy in 16.557578 seconds
pg_int64tostr in 8.070706 seconds
pg_int64tostr_new in 7.597320 seconds
pg_lltoa in 12.315339 seconds

david(at)ubuntu:~/C$ ./tostring_clang
pg_int64tostr_memcpy in 19.698807 seconds
pg_int64tostr in 12.800270 seconds
pg_int64tostr_new in 14.174052 seconds
pg_lltoa in 14.427803 seconds

Regards

David Rowley

--
David Rowley http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2015-09-03 13:06:09 September 2015 Commitfest
Previous Message Fujii Masao 2015-09-03 13:03:44 Re: max_worker_processes on the standby