Re: Making aggregate deserialization (and WAL receive) functions slightly faster
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Amit Kapila <amit.kapila16@gmail.com>,
Michael Paquier <michael@paquier.xyz>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2023-10-26T21:53:29Z
Lists: pgsql-hackers
Attachments
- use_initReadOnlyStringInfo_even_more.patch (text/plain) patch
On Thu, 26 Oct 2023 at 17:00, David Rowley <dgrowleyml@gmail.com> wrote: > Thanks for looking at this again. I fixed up each of those and pushed > the result, mentioning the incompatibility in the commit message. > > Now that that's done, I've attached a patch which makes use of the new > initReadOnlyStringInfo initializer function for the original case > mentioned when I opened this thread. I don't think there are any > remaining objections to this, but I'll let it sit for a bit to see. I've just pushed the deserial function optimisation patch. I was just looking at a few other places where we might want to make use of initReadOnlyStringInfo. * parallel.c in HandleParallelMessages(): Drilling into HandleParallelMessage(), I see the PqMsg_BackendKeyData case just reads a fixed number of bytes. In some of the other "switch" cases, I see calls pq_getmsgrawstring() either directly or indirectly. I see the counterpart to pq_getmsgrawstring() is pq_sendstring() which always appends the NUL char to the StringInfo, so I don't think not NUL terminating the received bytes is a problem as cstrings seem to be sent with the NUL terminator. This case just seems to handle ERROR/NOTICE messages coming from parallel workers. Not tuples themselves. It may not be that interesting a case to speed up. * applyparallelworker.c in HandleParallelApplyMessages(): Drilling into HandleParallelApplyMessage(), I don't see anything there that needs the input StringInfo to be NUL terminated. * worker.c in apply_spooled_messages(): Drilling into apply_dispatch() and going through each of the cases, I see logicalrep_read_tuple() pallocs a new buffer and ensures it's always NUL terminated which will be required in LOGICALREP_COLUMN_TEXT mode. (There seems to be further optimisation opportunities there where we could not do the palloc when in LOGICALREP_COLUMN_BINARY mode and just point value's buffer directly to the correct portion of the input StringInfo's buffer). * walreceiver.c in XLogWalRcvProcessMsg(): Nothing there seems to require the incoming_message StringInfo to have a NUL terminator. I imagine this one is the most worthwhile to do out of the 4. I've not tested to see if there are any performance improvements. Does anyone see any reason why we can't do the attached? David
Commits
-
Make use of initReadOnlyStringInfo() in more places
- ac7d6f5f831e 17.0 landed
-
Optimize various aggregate deserialization functions, take 2
- 0c882a298881 17.0 landed
-
Introduce the concept of read-only StringInfos
- f0efa5aec193 17.0 landed
-
Revert "Optimize various aggregate deserialization functions"
- 4f3b56eea235 17.0 landed
-
Optimize various aggregate deserialization functions
- 608fd198def5 17.0 landed