From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Alexander Kuzmenkov <a.kuzmenkov@postgrespro.ru>
Subject: Re: Performance improvements for src/port/snprintf.c
Date: Wed, 03 Oct 2018 14:01:35 -0400
Message-ID: <3316.1538589695@sss.pgh.pa.us> (raw)
In-Reply-To: <20181003174513.wxjxfj7eepytnlqa@alap3.anarazel.de>
References: <20181003155207.b3lqmovuv2c5c4id@alap3.anarazel.de>
<26510.1538582852@sss.pgh.pa.us>
<20181003161454.ozeioucsimjg5g6m@alap3.anarazel.de>
<27041.1538583733@sss.pgh.pa.us>
<20181003163717.oycshpp2hnctvtfj@alap3.anarazel.de>
<28321.1538585692@sss.pgh.pa.us>
<20181003170043.thdyezozi343dkuc@alap3.anarazel.de>
<2132.1538587869@sss.pgh.pa.us>
<20181003173639.tncawup2nnkp7vbv@alap3.anarazel.de>
<2435.1538588403@sss.pgh.pa.us>
<20181003174513.wxjxfj7eepytnlqa@alap3.anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> So when using pg's snprintf() to print a single floating point number
> with precision, we get nearly a 10% boost.
I just tested that using my little standalone testbed, and I failed
to replicate the result. I do see that strfromd is slightly faster,
but it's just a few percent measuring snprintf.c in isolation --- in
the overall context of COPY, I don't see how you get to 10% net savings.
So I continue to think there's something fishy about your test case.
BTW, so far as I can tell on F28, strfromd isn't exposed without
"-D__STDC_WANT_IEC_60559_BFP_EXT__", which seems fairly scary;
what else does that affect?
regards, tom lane
Attachments:hack-use-of-strfromd.patch (text/x-diff, 796B) downloaddiff --git a/src/port/snprintf.c b/src/port/snprintf.cindex b9b6add..f75369c 100644--- a/src/port/snprintf.c+++ b/src/port/snprintf.c@@ -1137,17 +1137,19 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
zeropadlen = precision - prec;
fmt[0] = '%';
fmt[1] = '.';
- fmt[2] = '*';- fmt[3] = type;- fmt[4] = '\0';- vallen = sprintf(convert, fmt, prec, value);+ fmt[2] = (prec / 100) + '0';+ fmt[3] = ((prec % 100) / 10) + '0';+ fmt[4] = (prec % 10) + '0';+ fmt[5] = type;+ fmt[6] = '\0';+ vallen = strfromd(convert, sizeof(convert), fmt, value);
}
else
{
fmt[0] = '%';
fmt[1] = type;
fmt[2] = '\0';
- vallen = sprintf(convert, fmt, value);+ vallen = strfromd(convert, sizeof(convert), fmt, value);
}
if (vallen < 0)
goto fail;
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, thomas.munro@enterprisedb.com, andrew@tao11.riddles.org.uk, a.kuzmenkov@postgrespro.ru
Subject: Re: Performance improvements for src/port/snprintf.c
In-Reply-To: <3316.1538589695@sss.pgh.pa.us>
* 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