Re: [PATCH] Optimize json_lex_string by batching character copying

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: [PATCH] Optimize json_lex_string by batching character copying
Дата
Msg-id 20220706051801.gfbzjxgflbsglyt6@awork3.anarazel.de
обсуждение исходный текст
Ответ на Re: [PATCH] Optimize json_lex_string by batching character copying  (John Naylor <john.naylor@enterprisedb.com>)
Ответы Re: [PATCH] Optimize json_lex_string by batching character copying  (John Naylor <john.naylor@enterprisedb.com>)
Список pgsql-hackers
Hi,

On 2022-07-06 12:10:20 +0700, John Naylor wrote:
> diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
> index eeedc0645a..ad4858c623 100644
> --- a/src/common/jsonapi.c
> +++ b/src/common/jsonapi.c
> @@ -851,10 +851,26 @@ json_lex_string(JsonLexContext *lex)
>          }
>          else if (lex->strval != NULL)
>          {
> +            /* start lookahead at next byte */
> +            char       *p = s + 1;
> +
>              if (hi_surrogate != -1)
>                  return JSON_UNICODE_LOW_SURROGATE;
>  
> -            appendStringInfoChar(lex->strval, *s);
> +            while (p < end)
> +            {
> +                if (*p == '\\' || *p == '"' || (unsigned char) *p < 32)
> +                    break;
> +                p++;
> +            }
> +
> +            appendBinaryStringInfo(lex->strval, s, p - s);
> +
> +            /*
> +             * s will be incremented at the top of the loop, so set it to just
> +             * behind our lookahead position
> +             */
> +            s = p - 1;
>          }
>      }
>  
> -- 
> 2.36.1

I think before committing something along those lines we should make the
relevant bits also be applicable when ->strval is NULL, as several functions
use that (notably json_in IIRC). Afaics we'd just need to move the strval
check to be around the appendBinaryStringInfo(). And it should simplify the
function, because some of the relevant code is duplicated outside as well...

Greetings,

Andres Freund



В списке pgsql-hackers по дате отправления:

Предыдущее
От: John Naylor
Дата:
Сообщение: Re: [PATCH] Optimize json_lex_string by batching character copying
Следующее
От: Andres Freund
Дата:
Сообщение: Re: AIX support - alignment issues