From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: Speedup usages of pg_*toa() functions
Date: Tue, 09 Jun 2020 11:08:34 +0100
Message-ID: <87lfkw7eao.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CAApHDvrm2A5x2uHYxsqriO2cUaGcFvND+ksC9e7Tjep0t2RK_A@mail.gmail.com>
References: <CAApHDvrm2A5x2uHYxsqriO2cUaGcFvND+ksC9e7Tjep0t2RK_A@mail.gmail.com>
>>>>> "David" == David Rowley <dgrowleyml@gmail.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.
i.e.
Datum
int8out(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(0);
char *result = palloc(MAXINT8LEN + 1);
pg_lltoa(val, result);
PG_RETURN_CSTRING(result);
}
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;
}
--
Andrew (irc:RhodiumToad)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: andrew@tao11.riddles.org.uk, dgrowleyml@gmail.com, andres@anarazel.de
Subject: Re: Speedup usages of pg_*toa() functions
In-Reply-To: <87lfkw7eao.fsf@news-spur.riddles.org.uk>
References: <CAApHDvrm2A5x2uHYxsqriO2cUaGcFvND+ksC9e7Tjep0t2RK_A@mail.gmail.com> <87lfkw7eao.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox