agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Use stack allocated StringInfoDatas, where possible
2+ messages / 1 participants
[nested] [flat]

* pgsql: Use stack allocated StringInfoDatas, where possible
@ 2025-11-06 02:00  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2025-11-06 02:00 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Use stack allocated StringInfoDatas, where possible

Various places that were using StringInfo but didn't need that
StringInfo to exist beyond the scope of the function were using
makeStringInfo(), which allocates both a StringInfoData and the buffer it
uses as two separate allocations.  It's more efficient for these cases to
use a StringInfoData on the stack and initialize it with initStringInfo(),
which only allocates the string buffer.  This also simplifies the cleanup,
in a few cases.

Author: Mats Kindahl <mats.kindahl@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/4379aac8-26f1-42f2-a356-ff0e886228d3@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6d0eba66275b125bf634bbdffda90c70856e3f93

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c     | 14 ++++-----
contrib/tcn/tcn.c                       | 19 ++++++------
src/backend/access/transam/xlogbackup.c | 34 ++++++++++-----------
src/backend/backup/basebackup.c         | 10 +++----
src/backend/commands/subscriptioncmds.c | 35 ++++++++++++----------
src/backend/utils/adt/json.c            | 53 +++++++++++++++++----------------
src/backend/utils/adt/jsonb.c           |  9 +++---
src/backend/utils/adt/jsonfuncs.c       | 18 +++++++----
src/backend/utils/adt/multirangetypes.c | 13 ++++----
src/backend/utils/adt/rangetypes.c      | 18 ++++++-----
src/backend/utils/adt/ruleutils.c       | 17 ++++++-----
src/backend/utils/adt/xml.c             | 34 ++++++++++-----------
12 files changed, 144 insertions(+), 130 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Use stack-allocated StringInfoDatas, where possible
@ 2026-04-12 22:43  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2026-04-12 22:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Use stack-allocated StringInfoDatas, where possible

6d0eba662 already did most of the changes, but some new ones snuck in
just prior to that commit, so these got missed.

Having these short-lived StringInfoDatas on the stack rather than having
them get palloc'd by makeStringInfo() is simply for performance as it
saves doing a 2nd palloc.

Since this code is new to v19, it makes sense to improve it now rather
than wait until we branch as having v19 and v20 differ here just makes it
harder to backpatch fixes in this area.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/adt4wpj4FZwR+S7I@ip-10-97-1-34.eu-west-3.compute.internal

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a63bbc811d41b3567eb37fe2636e660a852dbbf2

Modified Files
--------------
src/backend/replication/logical/sequencesync.c | 39 ++++++++++++++------------
1 file changed, 21 insertions(+), 18 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-04-12 22:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-11-06 02:00 pgsql: Use stack allocated StringInfoDatas, where possible David Rowley <drowley@postgresql.org>
2026-04-12 22:43 pgsql: Use stack-allocated StringInfoDatas, where possible David Rowley <drowley@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox