Repository navigation
Prebuilt binaries require PHP 8.4.27+ / 8.5.12+; build from source on older patches.
Performance
- Strings with non-ASCII text are validated 16 bytes at a time with SSSE3 on x86-64 or NEON on ARM64: on Chinese or Russian text,
fastjson_validate()runs about 1.8-2.2x faster,fastjson_decode()1.2-1.4x, andfastjson_encode()withJSON_UNESCAPED_UNICODEabout 2x; default encoding is 3-23% faster depending on how long the non-ASCII runs are. ASCII-only encoding is about 1.5% slower. - Reuse the verified ASCII prefix when measuring exact output sizes for large JSON strings, avoiding a redundant byte-by-byte scan before a late escape or UTF-8 character.
fastjson_pointer_set()no longer callszend_strtod()on every untouched real to check for overflow. For plain decimal reals, it skips conversion when the integer-digit count (excluding leading zeros) is at most 308 and that count plus the signed exponent is at most 308. This sufficient condition does not cover every finite real:0.01e309still goes throughzend_strtod(). The original float-heavy corpus measurements took 15–70% less time (canada.json20.2 → 6.2 ms); output and errors are unchanged.
Changed
-
Bundled yyjson is now upstream master
be9bd74, with local patches P-002 through P-010 re-applied. -
Remove the unused internal unlimited JSON Pointer resolver and simplify the shared depth-check path. PHP APIs and pointer limits are unchanged.
-
Linux and macOS prebuilt binaries are built against PHP 8.4.27 and 8.5.12 instead of 8.4.1 and 8.5.0, so they include the memory-limit stop under Fixed, and require PHP 8.4.27+ or 8.5.12+ (8.6 binaries stay on 8.6.0). This reverses the 0.10.2 oldest-patch build. On an earlier patch the extension refuses to start with the warning below; PIE still selects the prebuilt binary there, so upgrade PHP or build from source on those patches.
-
On Linux and macOS with PHP 8.3+, the extension refuses to start when the running PHP is an older patch release than the one it was compiled against, with a startup warning naming both versions, instead of loading and later ending the process with an undefined-symbol error. PHP reports
Unable to start fastjson moduleand exits; install a build for the running PHP version or build from source. Windows builds skip the check, since Windows resolves a missing import when the DLL loads. -
fastjson_encode()andfastjson_file_encode()throwValueErrorwhen$depthis outside the int range, on every supported PHP version, matching thejson_encode()check added in php-src GH-23589. Previously such a depth made every container fail with a depth error while a scalar still encoded.
Fixed
fastjson_pointer_set()reports a number whose exponent has no digits, such as[1e], with the same message, position, and error code asfastjson_decode()(no digit after exponent signat the exponent, orJSON_ERROR_UTF8when the byte there is malformed UTF-8), including theJsonExceptioncode. Previously it reported a position one byte later, orunexpected end of datawhen only one byte followed the number, as in[1e].- On PHP 8.2.35+, 8.3.36+, 8.4.27+, 8.5.12+, and 8.6, which defer memory-limit errors until an internal call returns, decoding, encoding,
fastjson_pointer_get(),fastjson_pointer_set(), andfastjson_merge_patch()no longer keep allocating aftermemory_limitis crossed. Previously a large or amplifying input ran to PHP's hard limit (by default twicememory_limit), which ends the process with exit status 137 without running shutdown functions; under FrankenPHP that kills the whole server. PHP now reports its usual memory-limit fatal error. The check is compiled in only when fastjson is built against those PHP versions' headers (they defineZEND_HAS_OOM); the prebuilt binaries are, see Changed. Peak memory can still exceedmemory_limitby the allocation in flight, such as one output-buffer growth, and a single allocation larger than the room left below the hard limit, such as encoding one very large string, still ends the process. - A malformed escape in a JSON string (a backslash followed by anything other than
"\/bfnrtoruplus four hex digits, such as"\x"or"\u12") now reportsJSON_ERROR_SYNTAX, asjson_decode()does, instead ofJSON_ERROR_UTF8. This applies tofastjson_decode(),fastjson_validate(),fastjson_file_decode(), the pointer helpers andfastjson_merge_patch(), including theJsonExceptioncode. An unpaired surrogate escape still reportsJSON_ERROR_UTF8. fastjson_decode()no longer reads an uninitialized byte whenJSON_INVALID_UTF8_IGNOREremoves every byte of an object key. The key still decodes as"", matchingjson_decode().
Build
- Prebuilt binaries for PHP 8.6: Linux glibc (x86_64, arm64) and macOS (arm64)
.sofiles built against PHP 8.6.0, and Windows x64 TS/NTS DLLs.