Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jibBU-0007kV-Rg for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2020 10:08:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jibBS-0002fC-HF for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2020 10:08:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jibBS-0002f5-A6 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2020 10:08:42 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jibBP-0004FV-J0 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2020 10:08:41 +0000 Received: from [192.168.127.1] (port=52976 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1jibBK-000C0o-Li; Tue, 09 Jun 2020 10:08:34 +0000 Received: from localhost ([127.0.0.1]:43868 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jibBK-0003HM-7j; Tue, 09 Jun 2020 10:08:34 +0000 From: Andrew Gierth To: David Rowley Cc: PostgreSQL Developers , Andres Freund Subject: Re: Speedup usages of pg_*toa() functions In-Reply-To: (David Rowley's message of "Tue, 9 Jun 2020 18:53:06 +1200") Message-ID: <87lfkw7eao.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Tue, 09 Jun 2020 11:08:34 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "David" == David Rowley 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)