Re: appendBinaryStringInfo stuff

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: appendBinaryStringInfo stuff
Дата
Msg-id CAApHDvo0Q9_6RdNxL_EgZhBAqEeTtLxd3m=G79movsNNNbByvA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: appendBinaryStringInfo stuff  (Andres Freund <andres@anarazel.de>)
Ответы Re: appendBinaryStringInfo stuff  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: appendBinaryStringInfo stuff  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
On Mon, 19 Dec 2022 at 21:12, Andres Freund <andres@anarazel.de> wrote:
> Perhaps we should make appendStringInfoString() a static inline function
> - most compilers can compute strlen() of a constant string at compile
> time.

I had wondered about that, but last time I looked into it there was a
small increase in the size of the binary from doing it. Perhaps it
does not matter, but it's something to consider.

Re-thinking, I wonder if we could use the same macro trick used in
ereport_domain(). Something like:

#ifdef HAVE__BUILTIN_CONSTANT_P
#define appendStringInfoString(str, s) \
    __builtin_constant_p(s) ? \
        appendBinaryStringInfo(str, s, sizeof(s) - 1) : \
        appendStringInfoStringInternal(str, s)
#else
#define appendStringInfoString(str, s) \
    appendStringInfoStringInternal(str, s)
#endif

and rename the existing function to appendStringInfoStringInternal.

Because __builtin_constant_p is a known compile-time constant, it
should be folded to just call the corresponding function during
compilation.

Just looking at the binary sizes for postgres. I see:

unpatched = 9972128 bytes
inline function = 9990064 bytes
macro trick = 9984968 bytes

I'm currently not sure why the macro trick increases the binary at
all. I understand why the inline function does.

David



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Common function for percent placeholder replacement
Следующее
От: Mikhail Gribkov
Дата:
Сообщение: Re: On login trigger: take three