]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Speed up byteain by not parsing traditional-style input twice.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Jul 2025 20:42:02 +0000 (16:42 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Jul 2025 20:42:10 +0000 (16:42 -0400)
commit3683af617044d271ab7486d43d06f9689ed4961d
tree64dbe2ef951553f0ff18e84a52f4c56bcdac5ded
parent84409ed640568d8ccaaf1df1a41fb02f37d026ed
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
src/backend/utils/adt/bytea.c
src/test/regress/expected/strings.out
src/test/regress/sql/strings.sql