Skip to content

Commit 212e5bc

Browse files
committed
configure: disable Apple clang size optimizations that hurt runtime speed
Apple clang enables the AArch64 machine outliner and hot/cold code splitting by default at -O2. Both trade speed for size: the outliner inserts extra bl/ret pairs into hot paths (measured inside the inlined zval destructor loops of zend_array_destroy, among others), and cold-split fragments (4700+ in a default cli build) are compiled for size, which mispredicted branch hints turn into slow hot code. Disabling both speeds up a CPU-bound static analysis workload (PHPStan analysing its own codebase, no opcache) by ~4% wall time on an Apple M-series machine. The flags are added only when the compiler accepts them (-Werror guards against clang's unknown -m flag warnings), so non-Apple toolchains are unaffected.
1 parent 43813f1 commit 212e5bc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ esac
219219
dnl See https://github.com/php/php-src/issues/14140
220220
AX_CHECK_COMPILE_FLAG([-ffp-contract=off], [CFLAGS="$CFLAGS -ffp-contract=off"])
221221

222+
dnl Apple clang enables the AArch64 machine outliner and hot/cold code
223+
dnl splitting by default at -O2. Both trade speed for size: outlining
224+
dnl inserts extra calls into hot paths (including the zval destructor
225+
dnl loops) and cold-split fragments are compiled for size. Disabling them
226+
dnl speeds up CPU-bound scripts measurably (~4% on a large static
227+
dnl analysis workload). -Werror is needed because clang only warns about
228+
dnl unknown -m flags.
229+
AX_CHECK_COMPILE_FLAG([-mno-outline],
230+
[CFLAGS="$CFLAGS -mno-outline"], [], [-Werror])
231+
AX_CHECK_COMPILE_FLAG([-Xclang -fno-split-cold-code],
232+
[CFLAGS="$CFLAGS -Xclang -fno-split-cold-code"], [], [-Werror])
233+
222234
dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4)
223235
dnl supports it. This can help reduce the binary size and startup time.
224236
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],

0 commit comments

Comments
 (0)