PG14: Avoid checking output-buffer-length for every encoded byte during pg_hex_encode
Hans Buschmann <buschmann@nidsa.net>
From: Hans Buschmann <buschmann@nidsa.net>
To: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2021-08-15T14:58:59Z
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 →
-
Revert refactoring of hex code to src/common/
- 1900c140554e 14.0 landed
- 2576dcfb76aa 15.0 landed
-
Rework refactoring of hex and encoding routines
- aef8948f38d9 14.0 cited
Attachments
- hex_encode_length_check_outside_loop.patch (application/octet-stream) patch
During some development on encoding-related parts of postgres I stumbled over the new length-checking-code in common/hex.c/pg_hex_encode. Differently when comparing it to all versions before the output-buffer-length is checked during encoding of every individual source byte. This may impose quite a regression when using pg_dump on databases with many/big bytea or lo columns. Because all criteria to check buffer-length are known in advance of encoding (srclen and destlen) I propose doing the check only once before starting the while-loop. Please find the attached patch for pg14 and master, older versions did not have this behavior. Tested on pg14-beta3, but applies also on master. PS: This is my very first patch, I am in no way an experienced C-developer and don't have a smoothly running development environment or experience yet. (originally mostly dealing with postgres on Windows). If it seems useful somebody could enter it as an open item / resolved item for pg14 after beta 3. Thanks for looking! Hans Buschmann