From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Speed up byteain by not parsing traditional-style input twice.
Date: Fri, 18 Jul 2025 20:42:18 +0000
Message-ID: <E1ucruM-006yYH-2A@gemulon.postgresql.org> (raw)
Speed up byteain by not parsing traditional-style input twice.
Instead of laboriously computing the exact output length, use strlen
to get an upper bound cheaply. (This is still O(N) of course, but
the constant factor is a lot less.) This will typically result in
overallocating the output datum, but that's of little concern since
it's a short-lived allocation in just about all use-cases.
A simple microbenchmark showed about 40% speedup for long input
strings.
While here, make some cosmetic cleanups and add a test case that
covers the double-backslash code path in byteain and byteaout.
Author: Steven Niu <niushiji@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Stepan Neretin <slpmcf@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/ca315729-140b-426e-81a6-6cd5cfe7ecc5@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/3683af617044d271ab7486d43d06f9689ed4961d
Modified Files
--------------
src/backend/utils/adt/bytea.c | 61 +++++++++--------------------------
src/test/regress/expected/strings.out | 12 +++++++
src/test/regress/sql/strings.sql | 2 ++
3 files changed, 30 insertions(+), 45 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Speed up byteain by not parsing traditional-style input twice.
In-Reply-To: <E1ucruM-006yYH-2A@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox