Merge pull request #143 from Alpaq92/lto-apple-clang
Build: link-time optimization on with Apple Clang; drop the LTO comparison
This commit is contained in:
@@ -416,45 +416,3 @@ jobs:
|
|||||||
path: dist-pkg/*.rpm
|
path: dist-pkg/*.rpm
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
lto:
|
|
||||||
name: linux lto ${{ matrix.cc }}
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
timeout-minutes: 90
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- { cc: gcc, cxx: g++, extra: '' }
|
|
||||||
- { cc: clang, cxx: clang++, extra: '-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld' }
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Start Debian
|
|
||||||
run: docker run -d --name debian -v "$PWD:/src" -w /src debian:bookworm sleep infinity
|
|
||||||
|
|
||||||
- name: Install packages
|
|
||||||
run: |
|
|
||||||
docker exec -i debian sh -eu <<'EOF2'
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
apt-get update </dev/null
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
cmake ninja-build gcc g++ clang lld llvm pkgconf file diffutils \
|
|
||||||
libx11-dev libxext-dev libxcursor-dev libxi-dev libxfixes-dev \
|
|
||||||
libxrandr-dev libxrender-dev libxtst-dev libxkbcommon-dev \
|
|
||||||
libwayland-dev wayland-protocols libegl-dev libdbus-1-dev \
|
|
||||||
dbus xvfb xauth </dev/null
|
|
||||||
EOF2
|
|
||||||
|
|
||||||
- name: Link-time optimization off and on
|
|
||||||
run: |
|
|
||||||
docker exec -i -e CC=${{ matrix.cc }} -e CXX=${{ matrix.cxx }} debian sh -eu <<'EOF2'
|
|
||||||
$CC --version | head -1
|
|
||||||
cmake --version | head -1
|
|
||||||
nproc
|
|
||||||
dbus-run-session -- sh tools/ci/lto-check.sh -x Xvfb -w "timeout 600" -- ${{ matrix.extra }}
|
|
||||||
EOF2
|
|
||||||
|
|||||||
@@ -138,8 +138,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
version='${{ inputs.version || 'dev' }}'
|
version='${{ inputs.version || 'dev' }}'
|
||||||
name="libreaktor-${version}-macos-${{ matrix.arch }}"
|
name="libreaktor-${version}-macos-${{ matrix.arch }}"
|
||||||
cmake --build build --target libreaktor </dev/null
|
cmake -S . -B build-lib -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_LTO=OFF -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||||
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
|
cmake --build build-lib --target libreaktor </dev/null
|
||||||
|
cmake --install build-lib --prefix "dist/$name" --component libreaktor </dev/null
|
||||||
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||||
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
|
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
|
||||||
cmake --build build-consumer </dev/null
|
cmake --build build-consumer </dev/null
|
||||||
@@ -281,31 +282,3 @@ jobs:
|
|||||||
path: dist/libreaktor-shared-*-macos-universal.zip
|
path: dist/libreaktor-shared-*-macos-universal.zip
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
lto:
|
|
||||||
name: macos lto ${{ matrix.arch }}
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
|
||||||
runs-on: ${{ matrix.runner }}
|
|
||||||
timeout-minutes: 90
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- { arch: arm64, runner: macos-15 }
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Install packages
|
|
||||||
env:
|
|
||||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
|
||||||
run: brew install ninja
|
|
||||||
|
|
||||||
- name: Link-time optimization off and on
|
|
||||||
run: |
|
|
||||||
cc --version | head -1
|
|
||||||
cmake --version | head -1
|
|
||||||
sysctl -n hw.ncpu
|
|
||||||
sh tools/ci/lto-check.sh
|
|
||||||
|
|||||||
+3
-2
@@ -154,8 +154,9 @@ endif()
|
|||||||
# longer runs faster or slower as the code linked before it changes size. The
|
# longer runs faster or slower as the code linked before it changes size. The
|
||||||
# objects hold the compiler's own form until the link, so a static library
|
# objects hold the compiler's own form until the link, so a static library
|
||||||
# meant for other compilers is built with it off, as tools/libreaktor-pkg.sh
|
# meant for other compilers is built with it off, as tools/libreaktor-pkg.sh
|
||||||
# does. Measured with MSVC only, so on there alone.
|
# does. On where it measured faster without new warnings: MSVC and Apple
|
||||||
if(MSVC)
|
# Clang. GCC warns in dependencies with it, and Clang on Linux gained nothing.
|
||||||
|
if(MSVC OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||||
set(_reaktor_lto_default ON)
|
set(_reaktor_lto_default ON)
|
||||||
else()
|
else()
|
||||||
set(_reaktor_lto_default OFF)
|
set(_reaktor_lto_default OFF)
|
||||||
|
|||||||
@@ -1219,7 +1219,7 @@ Passed to CMake, through either script:
|
|||||||
| `REAKTOR_RENDERERS` | empty | The renderers built beside `software`, in `--renderer`'s words, with commas or semicolons between: `direct3d11`, `direct3d12`, `opengl`, `opengles2`. Empty is the platform's default, `direct3d11,direct3d12` on Windows and nothing on Linux and the BSDs; `none` is software only, and a Windows program is then 105 KB smaller. macOS builds `metal` and `opengl` either way, the web `opengles2` |
|
| `REAKTOR_RENDERERS` | empty | The renderers built beside `software`, in `--renderer`'s words, with commas or semicolons between: `direct3d11`, `direct3d12`, `opengl`, `opengles2`. Empty is the platform's default, `direct3d11,direct3d12` on Windows and nothing on Linux and the BSDs; `none` is software only, and a Windows program is then 105 KB smaller. macOS builds `metal` and `opengl` either way, the web `opengles2` |
|
||||||
| `REAKTOR_SHADERS` | `OFF` | Build SDL's GPU API and its renderer, `--renderer sdl-gpu`, for an application's own shaders: Direct3D 12 on Windows, Metal on macOS, Vulkan on Linux and the BSDs; on, a program is 184 KB larger on Windows, and on Linux loads the Vulkan drivers even to draw in software |
|
| `REAKTOR_SHADERS` | `OFF` | Build SDL's GPU API and its renderer, `--renderer sdl-gpu`, for an application's own shaders: Direct3D 12 on Windows, Metal on macOS, Vulkan on Linux and the BSDs; on, a program is 184 KB larger on Windows, and on Linux loads the Vulkan drivers even to draw in software |
|
||||||
| `REAKTOR_SHARED` | `OFF` | Also build the [shared library](#in-your-own-project), and link the samples to it; Linux, the BSDs and macOS |
|
| `REAKTOR_SHARED` | `OFF` | Also build the [shared library](#in-your-own-project), and link the samples to it; Linux, the BSDs and macOS |
|
||||||
| `REAKTOR_LTO` | `ON` with MSVC | Link-time optimization in a Release build, where the toolchain supports it; never on the web. Its static library holds objects only the same compiler can link, so one for others is built with it `OFF`, as `tools/libreaktor-pkg.sh` and the Windows release do |
|
| `REAKTOR_LTO` | `ON` with MSVC and Apple Clang | Link-time optimization in a Release build, where the toolchain supports it; never on the web. Its static library holds objects only the same compiler can link, so one for others is built with it `OFF`, as `tools/libreaktor-pkg.sh` and the Windows and macOS releases do |
|
||||||
| `REAKTOR_SAMPLES`, `REAKTOR_TESTS` | `ON` at the top | Build the samples, and the tests in `tests/` |
|
| `REAKTOR_SAMPLES`, `REAKTOR_TESTS` | `ON` at the top | Build the samples, and the tests in `tests/` |
|
||||||
| `REAKTOR_INSTALL` | `ON` at the top | Install rules for libreaktor's files |
|
| `REAKTOR_INSTALL` | `ON` at the top | Install rules for libreaktor's files |
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -262,11 +262,12 @@ on 2026-11-10 against 0.10.0, `bench --no-vsync` renders a frame 8.9%
|
|||||||
faster (every one of twelve runs) and the showcase's pages, drawn every
|
faster (every one of twelve runs) and the showcase's pages, drawn every
|
||||||
frame, 4–8% faster. Pixels and `--a11y-dump` are unchanged. Its static
|
frame, 4–8% faster. Pixels and `--a11y-dump` are unchanged. Its static
|
||||||
library holds objects only the same compiler can link, so
|
library holds objects only the same compiler can link, so
|
||||||
`tools/libreaktor-pkg.sh` and the Windows release build one with it off.
|
`tools/libreaktor-pkg.sh` and the Windows and macOS releases build one with
|
||||||
|
it off.
|
||||||
|
|
||||||
With GCC and Clang it stays off. On GitHub runners on 2026-11-10,
|
**With Apple Clang it is on as well**; with GCC and Clang on Linux it stays
|
||||||
`tools/ci/lto-check.sh` built each twice and ran `bench --renderer software
|
off. On GitHub runners on 2026-11-10, a CI job (since removed) built each
|
||||||
--no-vsync` ten times each way, in turn; shots and dumps were the same both
|
twice and ran `bench --renderer software --no-vsync` ten times each way, in turn; shots and dumps were the same both
|
||||||
ways:
|
ways:
|
||||||
|
|
||||||
| Compiler | Render, 64 boxes | 512 boxes | `showcase` |
|
| Compiler | Render, 64 boxes | 512 boxes | `showcase` |
|
||||||
@@ -275,7 +276,9 @@ ways:
|
|||||||
| Clang 14.0, Linux x86-64 | 0.22 → 0.22 ms (2 of 10) | 0.35 → 0.34 ms (9 of 10) | +342,264 bytes (8.6%) |
|
| Clang 14.0, Linux x86-64 | 0.22 → 0.22 ms (2 of 10) | 0.35 → 0.34 ms (9 of 10) | +342,264 bytes (8.6%) |
|
||||||
| Apple Clang 17.0, macOS arm64 | 0.59 → 0.56 ms (9 of 10) | 0.865 → 0.795 ms (9 of 10) | +225,120 bytes (6.8%) |
|
| Apple Clang 17.0, macOS arm64 | 0.59 → 0.56 ms (9 of 10) | 0.865 → 0.795 ms (9 of 10) | +225,120 bytes (6.8%) |
|
||||||
|
|
||||||
With it, GCC also warns 69 times more, in kb_text_shape and FreeType.
|
With it, GCC also warns 69 times more, in kb_text_shape and FreeType, and
|
||||||
|
Clang on Linux gains nothing for its size. Apple Clang was measured on arm64
|
||||||
|
only.
|
||||||
|
|
||||||
SDL's GPU API is left out unless `REAKTOR_SHADERS` is on. Built in, it costs
|
SDL's GPU API is left out unless `REAKTOR_SHADERS` is on. Built in, it costs
|
||||||
the software renderer too: SDL then loads the Vulkan loader, every installed
|
the software renderer too: SDL then loads the Vulkan loader, every installed
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Builds twice, link-time optimization off and on, and compares the two:
|
|
||||||
# tests, shots and dumps, sizes, and bench frame times taken in turn.
|
|
||||||
# lto-check.sh [-x XVFB] [-w WRAP] [-r RUNS] [CMAKE_ARGS...]
|
|
||||||
set -u
|
|
||||||
|
|
||||||
xvfb=""
|
|
||||||
wrap=""
|
|
||||||
runs=10
|
|
||||||
while getopts x:w:r: opt; do
|
|
||||||
case $opt in
|
|
||||||
x) xvfb=$OPTARG ;;
|
|
||||||
w) wrap=$OPTARG ;;
|
|
||||||
r) runs=$OPTARG ;;
|
|
||||||
*) echo "usage: lto-check.sh [-x XVFB] [-w WRAP] [-r RUNS] [CMAKE_ARGS...]" >&2; exit 2 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $((OPTIND - 1))
|
|
||||||
|
|
||||||
tests=$(cat tools/ci/tests.txt)
|
|
||||||
for v in OFF ON; do
|
|
||||||
cmake -S . -B "build-lto-$v" -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_LTO=$v "$@" </dev/null >"lto-$v.cmake.log" 2>&1 || { cat "lto-$v.cmake.log"; exit 1; }
|
|
||||||
grep -i "LTO" "lto-$v.cmake.log" || :
|
|
||||||
cmake --build "build-lto-$v" --target showcase notepad simple bench $tests </dev/null >"lto-$v.build.log" 2>&1 || { tail -50 "lto-$v.build.log"; exit 1; }
|
|
||||||
echo "$v: $(grep -ci 'warning' "lto-$v.build.log") warning lines, $(grep -c -e '-flto' "build-lto-$v/build.ninja") -flto lines in build.ninja"
|
|
||||||
grep -i 'warning' "lto-$v.build.log" | sort | uniq -c | sort -rn | head -20
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -n "$xvfb" ]; then
|
|
||||||
"$xvfb" :96 -screen 0 1280x1024x24 -nolisten tcp </dev/null >lto-xvfb.log 2>&1 &
|
|
||||||
xvfb_pid=$!
|
|
||||||
trap 'kill "$xvfb_pid" 2>/dev/null || :' EXIT
|
|
||||||
n=0
|
|
||||||
while [ ! -S /tmp/.X11-unix/X96 ]; do
|
|
||||||
n=$((n + 1))
|
|
||||||
if [ "$n" -gt 120 ] || ! kill -0 "$xvfb_pid" 2>/dev/null; then
|
|
||||||
echo "Xvfb did not start"; cat lto-xvfb.log || :; exit 1
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
DISPLAY=:96
|
|
||||||
export DISPLAY
|
|
||||||
fi
|
|
||||||
|
|
||||||
fail=0
|
|
||||||
for v in OFF ON; do
|
|
||||||
for t in $tests; do
|
|
||||||
a=; [ "$t" = gibustest ] && [ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ] && a=--require-bus
|
|
||||||
$wrap "./build-lto-$v/$t" $a </dev/null >"lto-$v-$t.log" 2>&1 || { echo "$v $t: failed"; tail -20 "lto-$v-$t.log"; fail=1; }
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
rm -rf lto-shots
|
|
||||||
mkdir lto-shots
|
|
||||||
same=0
|
|
||||||
for t in 0 1 2 3 4 5 6 7 8 9; do
|
|
||||||
for th in light dark; do
|
|
||||||
for v in OFF ON; do
|
|
||||||
$wrap "./build-lto-$v/showcase" --tab $t --theme $th --shot "lto-shots/$v-$t-$th.bmp" --a11y-dump "lto-shots/$v-$t-$th.txt" </dev/null >/dev/null 2>&1
|
|
||||||
grep -v volatile "lto-shots/$v-$t-$th.txt" | grep -v '^#' >"lto-shots/$v-$t-$th.dump"
|
|
||||||
done
|
|
||||||
if [ -s "lto-shots/OFF-$t-$th.bmp" ] && cmp -s "lto-shots/OFF-$t-$th.bmp" "lto-shots/ON-$t-$th.bmp" &&
|
|
||||||
cmp -s "lto-shots/OFF-$t-$th.dump" "lto-shots/ON-$t-$th.dump"; then
|
|
||||||
same=$((same + 1))
|
|
||||||
else
|
|
||||||
echo "showcase tab $t $th: differs"; fail=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
for s in notepad simple; do
|
|
||||||
for v in OFF ON; do
|
|
||||||
$wrap "./build-lto-$v/$s" --theme light --shot "lto-shots/$v-$s.bmp" </dev/null >/dev/null 2>&1
|
|
||||||
done
|
|
||||||
if [ -s "lto-shots/OFF-$s.bmp" ] && cmp -s "lto-shots/OFF-$s.bmp" "lto-shots/ON-$s.bmp"; then same=$((same + 1)); else echo "$s: differs"; fail=1; fi
|
|
||||||
done
|
|
||||||
echo "shots and dumps the same: $same of 22"
|
|
||||||
|
|
||||||
for p in showcase bench; do
|
|
||||||
echo "$p bytes: off $(wc -c <"build-lto-OFF/$p") on $(wc -c <"build-lto-ON/$p")"
|
|
||||||
done
|
|
||||||
|
|
||||||
med() { sort -n | awk '{a[NR] = $1} END {print (NR % 2) ? a[(NR + 1) / 2] : (a[NR / 2] + a[NR / 2 + 1]) / 2}'; }
|
|
||||||
for boxes in 64 512; do
|
|
||||||
: >"lto-bench-$boxes.txt"
|
|
||||||
i=0
|
|
||||||
while [ "$i" -lt "$runs" ]; do
|
|
||||||
order="OFF ON"; [ $((i % 2)) -eq 1 ] && order="ON OFF"
|
|
||||||
for v in $order; do
|
|
||||||
$wrap "./build-lto-$v/bench" --renderer software --no-vsync --bench-seconds 5 --boxes $boxes </dev/null 2>/dev/null |
|
|
||||||
awk -v v=$v -v i=$i '/^ms_render/ {r = $2} /^ms_per_frame/ {f = $2} END {print i, v, r, f}' >>"lto-bench-$boxes.txt"
|
|
||||||
done
|
|
||||||
i=$((i + 1))
|
|
||||||
done
|
|
||||||
for v in OFF ON; do
|
|
||||||
echo "bench $boxes boxes, software, $v: render $(awk -v v=$v '$2 == v {print $3}' "lto-bench-$boxes.txt" | med) ms, frame $(awk -v v=$v '$2 == v {print $4}' "lto-bench-$boxes.txt" | med) ms"
|
|
||||||
done
|
|
||||||
echo "runs where on rendered faster: $(awk '{r[$1, $2] = $3} END {n = 0; for (k in r) {split(k, p, SUBSEP); if (p[2] == "ON" && r[p[1], "ON"] < r[p[1], "OFF"]) n++} print n}' "lto-bench-$boxes.txt") of $runs"
|
|
||||||
done
|
|
||||||
exit "$fail"
|
|
||||||
Reference in New Issue
Block a user