From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Proposal: add new API to stringinfo |
Date: | 2024-12-25 03:37:04 |
Message-ID: | 20241225.123704.1194662271286702010.ishii@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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
Attachment | Content-Type | Size |
---|---|---|
stringinfo.patch | text/x-patch | 2.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | vignesh C | 2024-12-25 03:44:11 | Re: Logical Replication of sequences |
Previous Message | Michael Paquier | 2024-12-25 03:00:59 | Re: Infinite loop in XLogPageRead() on standby |