Hi,
On 2022-06-24 14:33:00 +0700, John Naylor wrote:
> On Thu, Jun 23, 2022 at 9:06 PM Andres Freund <andres@anarazel.de> wrote:
> > It looks like there's quite a bit of low hanging fruits to optimize...
>
> Yeah, if escapes and control characters are rare, adding an SSE2 fast
> path would give a boost to json_lex_string: check 16 bytes at a time
> for those chars (plus the ending double-quote).
The biggest thing I see is building the string in bigger chunks. Doing a
separate appendStringInfoChar() for each input character is obviously bad for
performance. I'd bet a good chunk of the time attributed to json_lex_string()
in Jelte's flamegraph is actually setting up the external function call to
appendStringInfoChar(). Which then proceeds to do a check whether the buffer
needs to be enlarged and maintains the trailing null byte on every call.
Greetings,
Andres Freund