[php-src] PR #15075: Expose more string APIs

From: Date: Tue, 23 Jul 2024 04:54:44 +0000
Subject: [php-src] PR #15075: Expose more string APIs
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-27448@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/15075 Author: morrisonlevi The main motivation here is to increase the amount of ZEND_API functions for working with zend_string *. Rust extensions cannot easily access these static zend_always_inline functions. So this makes them available while also still forcing them to be inline in C. The secondary motivation is to shrink the size of the PHP binaries. It turns out that because many of these functions are forced inline, they actually bloat the binary. Consider code with a structure like this: ```c if (UNEXPECTED(...)) { ... zend_string_release(...); return FAILURE; } ``` In cases like this, you do not actually want to inline zend_string_release. GCC will tell you this, if you replace zend_always_inline with inline and turn on -Winline, with an error message like: ``` error: inlining failed in call to 'zend_string_release': call is unlikely and code size would grow [-Werror=inline] ``` So, in we want an inline version, and a non-inline version. Sometimes we name a thing x and the inline version of it x_inline. However, these are widely used APIs. So I left the inline version alone and added _outline for the non-inline version. I'm open to a better naming scheme. Lastly, -Winline -Werror has a lot of failures, as you might guess. This PR addresses a number of failures that fall into these classes that have nothing to do with strings, but cutting down the number of errors helped me iterate over the patch: 1. The function uses setjmp, so it cannot be inline. The inline gets removed. 2. The function is never inlined. For instance, if it has 3 usage sites, and the compiler fails to inline all 3, then I remove inline from this function. For these cases, the compiler was already not inlining the function. There shouldn't be any ill effect from this group of changes. ---- So what does the size look like after these changes? ```sh # master # ls -l sapi/cli/php -rwxr-xr-x 1 root root 26496168 Jul 23 01:21 sapi/cli/php # this PR # ls -l sapi/cli/php -rwxr-xr-x 1 root root 26482696 Jul 23 04:26 sapi/cli/php ``` It saves 13,472 bytes, despite adding ZEND_API functions. Performance should not be affected, but there may be a slight improvement (some unexpected code paths become smaller, which can have cache effects). If there is a regression, it would mean that an UNEXPECTED (whether implicit or explicit) code path is actually taken quite often in the benchmark, and I'd like to know more information.

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