pgsql: Micro-optimize JSONTYPE_NUMERIC code path in json.c.

Поиск
Список
Период
Сортировка
От Nathan Bossart
Тема pgsql: Micro-optimize JSONTYPE_NUMERIC code path in json.c.
Дата
Msg-id E1rBgjE-009FKn-Cp@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Micro-optimize JSONTYPE_NUMERIC code path in json.c.

This commit does the following:

* In datum_to_json_internal(), the call to IsValidJsonNumber() is
  replaced with simplified validation code.  This avoids an extra
  call to strlen() in this path, and it avoids validating the
  entire string (which is okay since we know we're dealing with a
  numeric data type's output).

* In datum_to_json_internal(), the call to escape_json() in the
  JSONTYPE_NUMERIC path is replaced with code that just surrounds
  the string with quotes.  In passing, some other nearby calls to
  appendStringInfo() have been replaced with similar code to avoid
  unnecessary calls to vsnprintf().

* In composite_to_json(), the length of the separator is now
  determined at compile time to avoid unnecessary calls to
  strlen().

On my machine, this speeds up a benchmark for the proposed COPY TO
(FORMAT json) command with many integers by upwards of 20%.  There
are likely other code paths that could be given a similar
treatment, but that is left as a future exercise.

Reviewed-by: Jeff Davis, Tom Lane, David Rowley, John Naylor
Discussion: https://postgr.es/m/20231207231251.GB3359478%40nathanxps13

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dc3f9bc549d4cc8cb1d4030bdc94e788d70fdcfe

Modified Files
--------------
src/backend/utils/adt/json.c | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)


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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: pgsql: Cache opaque handle for GUC option to avoid repeasted lookups.
Следующее
От: Peter Geoghegan
Дата:
Сообщение: pgsql: Fix nbtree backward scan race condition comments.