Re: Proposal: add new API to stringinfo - Mailing list pgsql-hackers

From David Rowley
Subject Re: Proposal: add new API to stringinfo
Date
Msg-id CAApHDvrxXG1yrELvi+ZKjEk9DvAo0j6y4Lr28aOuTqgw1zQvtQ@mail.gmail.com
Whole thread Raw
In response to Proposal: add new API to stringinfo  (Tatsuo Ishii <ishii@postgresql.org>)
List pgsql-hackers
On Wed, 25 Dec 2024 at 16:37, Tatsuo Ishii <ishii@postgresql.org> wrote:
> Currently the StringInfo package provides StringInfo object creation
> API with fixed length initial allocation size (1024 bytes). However,
> if we want to allocate much smaller size of initial allocation, this
> is waste of space.

I think it would be good to have some method to allow callers to
specify the initial size. I'm personally surprise that the 1024
setting has been ok with all callers so far. StringInfo has always
reminded me of C#'s StringBuilder class, which has an overloaded
constructor to allow callers to specify the initial size. It seems
they realised that the default size isn't always ideal, so I don't
find it surprising that we've realised that too.

If you have trouble convincing people we need this for some new
reason, then maybe you could review the existing callers to see if
some of the existing call sites make it any more convincing.

A very quick review, I found:

send_message_to_frontend() initStringInfo(&buf) 1024 is probably too big
HandleParallelMessages() seems to know exactly how many bytes are
needed. Can this use a read-only StringInfo?
send_feedback() seems to know what size of the buffer it needs
buf_init() knows the exact size.

I didn't review the patch in detail, but I think "initsize" would be a
better parameter name than "size".

David



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Proposal: add new API to stringinfo
Next
From: Umar Hayat
Date:
Subject: Re: Add XMLNamespaces to XMLElement