pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Alexander Kuzmenkov <a.kuzmenkov@postgrespro.ru>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Performance improvements for src/port/snprintf.c
Date: Wed, 03 Oct 2018 13:18:35 -0400
Message-ID: <1680.1538587115@sss.pgh.pa.us> (raw)
In-Reply-To: <30898.1538517873@sss.pgh.pa.us>
References: <15785.1536776055@sss.pgh.pa.us>
	<20180926220419.lorxpb564gakdjkz@alap3.anarazel.de>
	<20180926221814.el5nwmkez6zfmzbz@alap3.anarazel.de>
	<14302.1538005507@sss.pgh.pa.us>
	<20180926235821.zmpxqv66ob7v2ffi@alap3.anarazel.de>
	<15882.1538007944@sss.pgh.pa.us>
	<20180927004022.lfhffbj3roxzf5ca@alap3.anarazel.de>
	<20180927005705.shbl3n5hq3t65n2j@alap3.anarazel.de>
	<20180927011814.kpncoksuqq3gy44s@alap3.anarazel.de>
	<15652.1538011825@sss.pgh.pa.us>
	<20181002201328.kauaofescppm54gq@alap3.anarazel.de>
	<30898.1538517873@sss.pgh.pa.us>

I wrote:
> Andres Freund <andres@anarazel.de> writes:
>> - I know it's not new, but is it actually correct to use va_arg(args, int64)
>> for ATYPE_LONGLONG?

> Well, the problem with just doing s/int64/long long/g is that the
> code would then fail on compilers without a "long long" type.
> We could ifdef our way around that, but I don't think the code would
> end up prettier.

I spent a bit more time thinking about that point.  My complaint about
lack of long long should be moot given that we're now requiring C99.
So the two cases we need to worry about are (1) long long exists and
is 64 bits, and (2) long long exists and is wider than 64 bits.  In
case (1) there's nothing actively wrong with the code as it stands.
In case (2), if we were to fix the problem by s/int64/long long/g,
the result would be that we'd be doing the arithmetic for all
integer-to-text conversions in 128 bits, which seems likely to be
pretty expensive.

So a "real" fix would probably require having separate versions of
fmtint for long and long long.  I'm not terribly excited about
going there.  I can see it happening some day when/if we need to
use 128-bit math more extensively than today, but I do not think
that day is close.  (Are there *any* platforms where "long long"
is 128 bits today?)

Having said that, maybe there's a case for changing the type spec
in only the va_arg() call, and leaving snprintf's related local
variables as int64.  (Is that what you actually meant?)  Then,
if long long really is different from int64, at least we have
predictable truncation behavior after fetching the value, rather
than undefined behavior while fetching it.

			regards, tom lane




view thread (65+ messages)  latest in thread

Message-ID: <1680.1538587115@sss.pgh.pa.us>
Permalink:  ../1680.1538587115@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1680.1538587115@sss.pgh.pa.us

 · 

reply

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, a.kuzmenkov@postgrespro.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Performance improvements for src/port/snprintf.c
  In-Reply-To: <1680.1538587115@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