Re: Speedup usages of pg_*toa() functions

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Speedup usages of pg_*toa() functions
Date: 2020-06-09 14:31:35
Message-ID: CAEudQApyRFg=anQGx6Qqt50GnDtZkU2L335140gnA=ZTb28tvA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em ter., 9 de jun. de 2020 às 07:55, David Rowley <dgrowleyml(at)gmail(dot)com>
escreveu:

> On Tue, 9 Jun 2020 at 22:08, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
> wrote:
> >
> > >>>>> "David" == David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> >
> > David> This allows us to speed up a few cases. int2vectorout() should
> > David> be faster and int8out() becomes a bit faster if we get rid of
> > David> the strdup() call and replace it with a palloc()/memcpy() call.
> >
> > What about removing the memcpy entirely? I don't think we save anything
> > much useful here by pallocing the exact length, rather than doing what
> > int4out does and palloc a fixed size and convert the int directly into
> > it.
>
> On looking back through git blame, it seems int2out and int4out have
> been that way since at least 1996, before int8.c existed. int8out has
> been doing it since fa838876e9f -- Include 8-byte integer type. dated
> 1998. Quite likely the larger than required palloc size back then was
> more of a concern. So perhaps you're right about just doing it that
> way instead. With that and the ints I tested with, the int8
> performance should be about aligned to int4 performance.
>
> > For pg_ltoa, etc., I don't like adding the extra call to pg_ultoa_n - at
> > least on my clang, that results in two copies of pg_ultoa_n inlined.
> > How about doing it like,
> >
> > int
> > pg_lltoa(int64 value, char *a)
> > {
> > int len = 0;
> > uint64 uvalue = value;
> >
> > if (value < 0)
> > {
> > uvalue = (uint64) 0 - uvalue;
> > a[len++] = '-';
> > }
> > len += pg_ulltoa_n(uvalue, a + len);
> > a[len] = '\0';
> > return len;
> > }
>
> Written like that, wouldn't it get better?

int
pg_lltoa(int64 value, char *a)
{
if (value < 0)
{
int len = 0;
uint64 uvalue = (uint64) 0 - uvalue;

a[len++] = '-';
len += pg_ulltoa_n(uvalue, a + len);
a[len] = '\0';
return len;
}
else
return pg_ulltoa_n(value, a);
}

regards,
Ranier Vilela

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2020-06-09 14:35:08 Re: Terminate the idle sessions
Previous Message David G. Johnston 2020-06-09 14:25:01 Re: Postgres installer with pgAdmin 4.22