pgsql: Build de-escaped JSON strings in larger chunks during lexing

Started by John Naylorabout 4 years ago3 messagescomitters
Jump to latest
#1John Naylor
john.naylor@enterprisedb.com

Build de-escaped JSON strings in larger chunks during lexing

During COPY BINARY with large JSONB blobs, it was found that half
the time was spent parsing JSON, with much of that spent in separate
appendStringInfoChar() calls for each input byte.

Add lookahead loop to json_lex_string() to allow batching multiple bytes
via appendBinaryStringInfo(). Also use this same logic when de-escaping
is not done, to avoid code duplication.

Report and proof of concept patch by Jelte Fennema, reworked by Andres
Freund and John Naylor

Discussion: /messages/by-id/CAGECzQQuXbies_nKgSiYifZUjBk6nOf2=TSXqRjj2BhUh8CTeA@mail.gmail.com
Discussion: /messages/by-id/PR3PR83MB0476F098CBCF68AF7A1CA89FF7B49@PR3PR83MB0476.EURPRD83.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3838fa269c15706df2b85ce2d6af8aacd5611655

Modified Files
--------------
src/common/jsonapi.c | 58 +++++++++++++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 19 deletions(-)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: John Naylor (#1)
Re: pgsql: Build de-escaped JSON strings in larger chunks during lexing

John Naylor <john.naylor@postgresql.org> writes:

Build de-escaped JSON strings in larger chunks during lexing

It looks like this broke buildfarm member skink (valgrind).

regards, tom lane

#3John Naylor
john.naylor@enterprisedb.com
In reply to: Tom Lane (#2)
Re: pgsql: Build de-escaped JSON strings in larger chunks during lexing

On Tue, Jul 12, 2022 at 5:15 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

It looks like this broke buildfarm member skink (valgrind).

Looking...

--
John Naylor
EDB: http://www.enterprisedb.com