Proposal: add new API to stringinfo
Tatsuo Ishii <ishii@postgresql.org>
From: Tatsuo Ishii <ishii@postgresql.org>
To: pgsql-hackers@postgresql.org
Date: 2024-12-25T03:37:04Z
Lists: pgsql-hackers
Attachments
- stringinfo.patch (text/x-patch) patch
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. Background: While working on this: https://www.postgresql.org/message-id/20241219.151950.488757175470671324.ishii%40postgresql.org I need to create lots of StringInfo many (like 100k) objects if a Window frame has that number of rows. In this case postgres allocates 1024 * 100k = 97.7MB of memory, which is too much because I usually only need 10 or so bytes for each StringInfo data buffer. To solve the problem I need to hack the internal of StringInfo object like this. len = 10; str = makeStringInfo(); pfree(encoded_str->data); str->data = (char *)palloc0(len); str->maxlen = len; This is not only ugly but breaks interface boundary. If we have another API like makeStringInfoWithSize(), I could do that in much better and simple way: len = 10; str = makeStringInfoWithSize(len); Attached is a patch to implement it. In the patch I add two new APIs. extern StringInfo makeStringInfoWithSize(int size); extern void initStringInfoWithSize(StringInfo str, int size); Maybe I could re-invent the wheel by copying stringinfo.c, but I think there are some uses cases like me, and it could justify in adding more code to stringinfo.c. Best reagards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add new StringInfo APIs to allow callers to specify the buffer size.
- a9dcbb4d5c00 18.0 landed