From f0ee708a13d1d4cc218f02a4cbeb949a239193d9 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 10 Jul 2026 10:39:51 +0200 Subject: [PATCH] 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. --- configure.ac | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/configure.ac b/configure.ac index 3229e0dac040..f190f4e1c682 100644 --- a/configure.ac +++ b/configure.ac @@ -219,6 +219,18 @@ esac dnl See https://github.com/php/php-src/issues/14140 AX_CHECK_COMPILE_FLAG([-ffp-contract=off], [CFLAGS="$CFLAGS -ffp-contract=off"]) +dnl Apple clang enables the AArch64 machine outliner and hot/cold code +dnl splitting by default at -O2. Both trade speed for size: outlining +dnl inserts extra calls into hot paths (including the zval destructor +dnl loops) and cold-split fragments are compiled for size. Disabling them +dnl speeds up CPU-bound scripts measurably (~4% on a large static +dnl analysis workload). -Werror is needed because clang only warns about +dnl unknown -m flags. +AX_CHECK_COMPILE_FLAG([-mno-outline], + [CFLAGS="$CFLAGS -mno-outline"], [], [-Werror]) +AX_CHECK_COMPILE_FLAG([-Xclang -fno-split-cold-code], + [CFLAGS="$CFLAGS -Xclang -fno-split-cold-code"], [], [-Werror]) + dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4) dnl supports it. This can help reduce the binary size and startup time. AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],