[php-src] PR #13974: Remove zend_strtod mutex

From: Date: Mon, 15 Apr 2024 17:39:27 +0000
Subject: [php-src] PR #13974: Remove zend_strtod mutex
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-25765@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/13974 Author: arnaud-lb zend_strtod.c uses a global state (mostly an allocation freelist) protected by a mutex in ZTS builds. This state is used by zend_dtoa(). This creates a lot of contention in concurrent loads. zend_dtoa() is used to format floats to string, e.g. in sprintf, json_encode, serialize, uniqid. In this PR I move the global state to the thread specific executor_globals and remove the mutex. The impact on non-concurrent environments is null or negligible, but there is a considerable speed up on concurrent environments, especially on Alpine/Musl. The frankenphp-demo is sped up 10% under apache/musl, 20% under FrankenPHP/glibc, and 40% under FrankenPHP/musl. Some synthetic benchmark is 80% faster. <details> <summary>Benchmarks:</summary> I'm using two benchmarks: - [frankenphp-demo](https://github.com/dunglas/frankenphp-demo) (requesting /api/monsters.jsonld). In this benchmark, frankenphp is setup in dev mode - [json_encode.php](https://gist.github.com/arnaud-lb/602ee3a0b6d96edbed2ed6aa5cf0d553) is a synthetic benchmark encoding an array or 100 floats In 3 separate environments: - php-cgi without concurrency - Apache mpm_event mod_php ZTS (100 concurrent requests) - Frankenphp in worker mode (100 concurrent requests) Bookworm uses glibc, Alpine uses musl. Results: php-cgi -T10,500 frankenphp-demo repeated 5 times: ``` master-bookworm: mean: 1.7227; stddev: 0.0035; diff: +0.00% (baseline) branch-bookworm: mean: 1.7195; stddev: 0.0037; diff: -0.19% master-alpine: mean: 1.8676; stddev: 0.0031; diff: -0.00% (baseline) branch-alpine: mean: 1.8700; stddev: 0.0029; diff: +0.13% master-zts-bookworm: mean: 1.7909; stddev: 0.0026; diff: -0.00% (baseline) branch-zts-bookworm: mean: 1.7943; stddev: 0.0014; diff: +0.19% master-zts-alpine: mean: 1.9928; stddev: 0.0059; diff: -0.00% (baseline) branch-zts-alpine: mean: 1.9900; stddev: 0.0031; diff: -0.14% ``` Also in Valgrind: ``` valgrind php-cgi -T1,10: master-bookworm: mean: 1200273448.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-bookworm: mean: 1200174784.0000; stddev: 0.0000; diff: -0.01% master-alpine: mean: 1193572485.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-alpine: mean: 1193577574.0000; stddev: 0.0000; diff: +0.00% master-zts-bookworm: mean: 1245688708.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-zts-bookworm: mean: 1245684830.0000; stddev: 0.0000; diff: -0.00% master-zts-alpine: mean: 1275329963.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-zts-alpine: mean: 1275302862.0000; stddev: 0.0000; diff: -0.00% ``` php-cgi -T10,5000 json_encode.php repeated 5 times: ``` master-bookworm: mean: 0.2541; stddev: 0.0003; diff: -0.00% (baseline) branch-bookworm: mean: 0.2532; stddev: 0.0002; diff: -0.33% master-alpine: mean: 0.2694; stddev: 0.0057; diff: +0.00% (baseline) branch-alpine: mean: 0.2702; stddev: 0.0098; diff: +0.30% master-zts-bookworm: mean: 0.4092; stddev: 0.0014; diff: -0.00% (baseline) branch-zts-bookworm: mean: 0.2665; stddev: 0.0023; diff: -34.86% master-zts-alpine: mean: 0.5691; stddev: 0.0015; diff: -0.00% (baseline) branch-zts-alpine: mean: 0.2862; stddev: 0.0006; diff: -49.71% ``` Valgrind: ``` master-bookworm: mean: 67901890.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-bookworm: mean: 68082973.0000; stddev: 0.0000; diff: +0.27% master-alpine: mean: 39943906.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-alpine: mean: 40117586.0000; stddev: 0.0000; diff: +0.43% master-zts-bookworm: mean: 74304991.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-zts-bookworm: mean: 69262486.0000; stddev: 0.0000; diff: -6.79% master-zts-alpine: mean: 45453755.0000; stddev: 0.0000; diff: +0.00% (baseline) branch-zts-alpine: mean: 41906922.0000; stddev: 0.0000; diff: -7.80% ``` Apache mpm_event mod_php ZTS frankenphp-demo: ``` master-zts-bookworm: 10.863000; +0.00% (baseline) branch-zts-bookworm: 10.876000; +0.12% master-zts-alpine: 12.218000; +0.00% (baseline) branch-zts-alpine: 10.885000; -10.91% ``` Apache mpm_event mod_php ZTS json_encode.php: ``` master-zts-bookworm: 1.476000; +0.00% (baseline) branch-zts-bookworm: 0.228000; -84.55% master-zts-alpine: 1.499000; +0.00% (baseline) branch-zts-alpine: 0.243000; -83.79% ``` FrankenPHP frankenphp-demo: ``` master-bookworm: 77 +0.00% (baseline) branch-bookworm: 62 -18.99% master-alpine: 120 +0.00% (baseline) branch-alpine: 68 -43.57% ``` </details>

« previous php.git-pulls (#25765) next »