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

From Tatsuo Ishii
Subject Re: Proposal: add new API to stringinfo
Date
Msg-id 20250105.105129.529148451853216562.ishii@postgresql.org
Whole thread Raw
In response to Re: Proposal: add new API to stringinfo  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
> 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

I looked into send_feedback(). Maybe with the new API we could do
something like attached?

> 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
> 
>
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 334bf3e7aff..66cc4ec49a1 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -3885,8 +3885,10 @@ send_feedback(XLogRecPtr recvpos, bool force, bool requestReply)
     if (!reply_message)
     {
         MemoryContext oldctx = MemoryContextSwitchTo(ApplyContext);
-
-        reply_message = makeStringInfo();
+        int        initsize = 
+            sizeof(char) + sizeof(int64) * 3 +
+            sizeof(TimestampTz) + sizeof(bool) + 1;
+        reply_message = makeStringInfoExtended(initsize);
         MemoryContextSwitchTo(oldctx);
     }
     else

pgsql-hackers by date:

Previous
From: Alena Rybakina
Date:
Subject: Re: Vacuum statistics
Next
From: Gurjeet Singh
Date:
Subject: Re: Proposal: add new API to stringinfo