wiki.techinc.nl/includes/json
Kevin Israel 210a34369a FormatJson: Optimize encode() for supported PHP versions
- Removed the str_replace() call to replace unescaped line terminators
  if UTF8_OK is set. PHP 7.1 and later escape these by default.

  The speedup isn't much at all (about 1% in my testing when encoding an
  API siteinfo result taken from enwiki). Perhaps it's not surprising
  given the way str_replace() works[1]. Still, it's better not to spend
  CPU time looking for characters that will not occur.

- Changed the algorithm for the optional spaces-to-tabs conversion when
  pretty printing. Instead of replacing one indent level throughout the
  entire string before replacing the next level, use a regex to replace
  in one pass. This is usually faster now that PHP 7 enables PCRE's JIT
  compiler by default. Without JIT, the regex was often slower.

  The speedup can be large for deeply nested data. For example, in my
  testing the languages/i18n data took about 8% less time to encode as
  tab-indented JSON, yet the API site info result took about 45% less.
  (This, of course, isn't actually relevant to the API even when pretty
  printed output is requested, because ApiFormatJson uses the default
  indent string of four spaces, which will always be faster unless
  support for tab indentation is added to PHP's json extension.)

- Set options using if statements instead of the ternary operator. This
  is the clearer way, and maybe the slightly faster one, skipping the
  assignment when the flags do not need to be set.

[1]: https://github.com/php/php-src/blob/PHP-8.0.10/ext/standard/string.c#L2969

Change-Id: Iebb1df0264e335a1819956710eeacf6d6b8f1471
2021-08-20 08:03:11 -04:00
..
FormatJson.php FormatJson: Optimize encode() for supported PHP versions 2021-08-20 08:03:11 -04:00
JsonCodec.php build: Updating dependencies 2021-07-22 03:36:05 +00:00
JsonConstants.php
JsonSerializer.php
JsonUnserializable.php
JsonUnserializableTrait.php build: Updating dependencies 2021-07-22 03:36:05 +00:00
JsonUnserializer.php build: Updating dependencies 2021-07-22 03:36:05 +00:00