From ecc25a3d6e46a70f119d9180600ad0368432a82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 21:43:11 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20perf(ci):=20the=20deploy=20build?= =?UTF-8?q?s=20thin,=20and=20the=20CLI=20is=20built=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `release` optimizes the whole program in one non-parallel pass, which is the right trade for something CPU-bound and the wrong one for a server that spends its time in SQLite, TLS and the network. `dist` inherits it with thin LTO and the cores actually used; `release` is untouched for when the last few percent are worth the wait. Measured on twelve cores: the relink every deploy pays for goes from 2m27s to 25s, a full build from 5m01s to 2m04s. The binary grows 32MB to 43MB before stripping, which nothing here is bounded by. The topcoat CLI is compiled from source on every run and changes only when its pinned version does, so it is cached on that version alone. --- .github/workflows/main.yml | 33 +++++++++++++++++++++++++-------- Cargo.toml | 10 ++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3dd1672..5be217c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,13 @@ env: TARGET: x86_64-unknown-linux-musl # The systemd user unit that owns the process. See izlek.service. SERVICE: izlek + # `release` keeps fat LTO in one codegen unit for when the last few percent + # are worth five minutes. `dist` is that profile with thin LTO and the cores + # actually used: measured on a 12-core machine, the relink every deploy pays + # for goes from 2m27s to 25s, for a binary this server will never be + # CPU-bound on. See the profile in Cargo.toml. + PROFILE: dist + TOPCOAT: 0.6.2 jobs: deploy: @@ -37,10 +44,20 @@ jobs: with: cache-all-crates: true + # Compiling the CLI from source costs minutes and it changes only when + # the pinned version does, so it is cached on that version alone. + - name: Cache the topcoat CLI + id: topcoat-cache + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/topcoat + key: topcoat-cli-${{ env.TOPCOAT }}-${{ runner.os }} + - name: Install the topcoat CLI # Installed before the cargo config below exists, so the CLI itself is # built for the host and not for musl. - run: cargo install topcoat-cli@0.6.2 --locked + if: steps.topcoat-cache.outputs.cache-hit != 'true' + run: cargo install topcoat-cli@${{ env.TOPCOAT }} --locked - name: Point cargo at musl run: | @@ -60,12 +77,12 @@ jobs: - name: Build the binary and bundle its assets run: | set -euo pipefail - # One compile: this builds izlek-web with the release profile and - # writes out the asset bundle embedded in the binary it produced. - topcoat asset bundle --package izlek-web --release --out dist/assets - cp "target/$TARGET/release/izlek-web" dist/izlek-web - strip dist/izlek-web - ls -l dist dist/assets + # One compile: this builds izlek-web and writes out the asset bundle + # embedded in the binary it produced. + topcoat asset bundle --package izlek-web --profile "$PROFILE" --out stage/assets + cp "target/$TARGET/$PROFILE/izlek-web" stage/izlek-web + strip stage/izlek-web + ls -l stage stage/assets - name: Install SSH keys run: | @@ -94,7 +111,7 @@ jobs: rm -rf -- '${deploy_path}/current.new' mkdir -p -- '${deploy_path}/current.new' " - tar -C dist -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'" + tar -C stage -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'" - name: Swap and restart run: | diff --git a/Cargo.toml b/Cargo.toml index ab6bdc5..df2414e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,13 @@ toml = "1" [profile.release] codegen-units = 1 lto = true + +# What the deploy builds. Fat LTO and one codegen unit buy the last few +# percent by optimizing the whole program in a single non-parallel pass — +# worth it for something CPU-bound, not for a server whose time goes to +# SQLite, TLS and the network. Thin LTO still optimizes across crates, in +# parallel, so `release` stays available for when the trade is worth making. +[profile.dist] +inherits = "release" +lto = "thin" +codegen-units = 16