Re: Avoid unnecessary StringInfo allocation in tablesync COPY buffer

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: Álvaro Herrera <alvherre@kurilemu.de>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>, David Rowley <dgrowleyml@gmail.com>, Fujii Masao <masao.fujii@gmail.com>
Date: 2026-05-11T07:09:21Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Use stack-allocated StringInfoDatas, where possible

Attachments


> On May 9, 2026, at 23:35, Álvaro Herrera <alvherre@kurilemu.de> wrote:
> 
> Hello,
> 
> On 2026-May-09, Chao Li wrote:
> 
>> I found this issue while reviewing the patch [1] and was suggested use
>> a separate thread for the issue.
>> 
>> In tablesync.c, copy_table() currently does:
>> ```
>>   copybuf = makeStringInfo();
>> ```
>> 
>> But copybuf is only used by copy_read_data(), and there it's really
>> just acting as a small state holder for data, len, and cursor, rather
>> than as a normal growable StringInfo.
> 
> I find this coding pattern weird and ugly and confusing.  If what we
> need is three variables, shouldn't we have three variables instead of
> this strange misuse of the StringInfo abstraction?
> 

Yep, I first considered adding a file-local structure, but decided to keep the changes minimal in the first version.

In v2, I switched to using a small file-local CopyBuf structure.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/