postgresql/src
Nathan Bossart dc3f9bc549 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
2023-12-08 13:39:08 -06:00
..
backend Micro-optimize JSONTYPE_NUMERIC code path in json.c. 2023-12-08 13:39:08 -06:00
bin Fix path of regress shared library in pg_upgrade test 2023-12-08 10:36:23 +09:00
common Shrink Unicode category table. 2023-12-07 15:44:03 -08:00
fe_utils Remove unneeded assignments in for loop header 2023-11-21 16:10:27 +01:00
include Cache opaque handle for GUC option to avoid repeasted lookups. 2023-12-08 11:16:01 -08:00
interfaces Fix handling of errors in libpq pipelines 2023-12-05 12:43:24 +01:00
makefiles Remove distprep 2023-11-06 15:18:04 +01:00
pl Don't specify number of dimensions in cases where we don't know it. 2023-11-17 11:29:46 -05:00
port Optimize pg_readv/pg_pwritev single vector case. 2023-11-29 17:19:25 +13:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Optimize nbtree backward scan boundary cases. 2023-12-08 11:05:17 -08:00
timezone Remove distprep 2023-11-06 15:18:04 +01:00
tools Cache opaque handle for GUC option to avoid repeasted lookups. 2023-12-08 11:16:01 -08:00
tutorial Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Don't clean initdb files on template creation failure 2023-12-08 13:42:54 +01:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00