PG14: Avoid checking output-buffer-length for every encoded byte during pg_hex_encode

From: Hans Buschmann <buschmann(at)nidsa(dot)net>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: PG14: Avoid checking output-buffer-length for every encoded byte during pg_hex_encode
Date: 2021-08-15 14:58:59
Message-ID: 1629039545467.80333@nidsa.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
hex_encode_length_check_outside_loop.patch application/octet-stream 1.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhihong Yu 2021-08-15 16:41:17 Re: Keep notnullattrs in RelOptInfo (Was part of UniqueKey patch series)
Previous Message Justin Pryzby 2021-08-15 14:44:55 Re: prion failed with ERROR: missing chunk number 0 for toast value 14334 in pg_toast_2619