forge
Explore
Log in

Don't you dare go Hollow

The deploy builds thin, and the CLI is built once

Browse files at this commit

ecc25a3d6e46a70f119d9180600ad0368432a82aAhmet Kaan GümüşParent: 97e9050
  • perf
    • the deploy builds thin, and the CLI is built once
Show full message
👷 perf(ci): the deploy builds thin, and the CLI is built once

`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.ymlmodified+25 -8
@@ -15,6 +15,13 @@ env:
1515 TARGET: x86_64-unknown-linux-musl
1616 # The systemd user unit that owns the process. See izlek.service.
1717 SERVICE: izlek
18+ # `release` keeps fat LTO in one codegen unit for when the last few percent
19+ # are worth five minutes. `dist` is that profile with thin LTO and the cores
20+ # actually used: measured on a 12-core machine, the relink every deploy pays
21+ # for goes from 2m27s to 25s, for a binary this server will never be
22+ # CPU-bound on. See the profile in Cargo.toml.
23+ PROFILE: dist
24+ TOPCOAT: 0.6.2
1825
1926 jobs:
2027 deploy:
@@ -37,10 +44,20 @@ jobs:
3744 with:
3845 cache-all-crates: true
3946
47+ # Compiling the CLI from source costs minutes and it changes only when
48+ # the pinned version does, so it is cached on that version alone.
49+ - name: Cache the topcoat CLI
50+ id: topcoat-cache
51+ uses: actions/cache@v4
52+ with:
53+ path: ~/.cargo/bin/topcoat
54+ key: topcoat-cli-${{ env.TOPCOAT }}-${{ runner.os }}
55+
4056 - name: Install the topcoat CLI
4157 # Installed before the cargo config below exists, so the CLI itself is
4258 # built for the host and not for musl.
43- run: cargo install topcoat-cli@0.6.2 --locked
59+ if: steps.topcoat-cache.outputs.cache-hit != 'true'
60+ run: cargo install topcoat-cli@${{ env.TOPCOAT }} --locked
4461
4562 - name: Point cargo at musl
4663 run: |
@@ -60,12 +77,12 @@ jobs:
6077 - name: Build the binary and bundle its assets
6178 run: |
6279 set -euo pipefail
63- # One compile: this builds izlek-web with the release profile and
64- # writes out the asset bundle embedded in the binary it produced.
65- topcoat asset bundle --package izlek-web --release --out dist/assets
66- cp "target/$TARGET/release/izlek-web" dist/izlek-web
67- strip dist/izlek-web
68- ls -l dist dist/assets
80+ # One compile: this builds izlek-web and writes out the asset bundle
81+ # embedded in the binary it produced.
82+ topcoat asset bundle --package izlek-web --profile "$PROFILE" --out stage/assets
83+ cp "target/$TARGET/$PROFILE/izlek-web" stage/izlek-web
84+ strip stage/izlek-web
85+ ls -l stage stage/assets
6986
7087 - name: Install SSH keys
7188 run: |
@@ -94,7 +111,7 @@ jobs:
94111 rm -rf -- '${deploy_path}/current.new'
95112 mkdir -p -- '${deploy_path}/current.new'
96113 "
97- tar -C dist -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'"
114+ tar -C stage -czf - . | ssh "$ssh_target" "tar -xzf - -C '${deploy_path}/current.new'"
98115
99116 - name: Swap and restart
100117 run: |
Cargo.tomlmodified+10 -0
@@ -28,3 +28,13 @@ toml = "1"
2828 [profile.release]
2929 codegen-units = 1
3030 lto = true
31+
32+# What the deploy builds. Fat LTO and one codegen unit buy the last few
33+# percent by optimizing the whole program in a single non-parallel pass —
34+# worth it for something CPU-bound, not for a server whose time goes to
35+# SQLite, TLS and the network. Thin LTO still optimizes across crates, in
36+# parallel, so `release` stays available for when the trade is worth making.
37+[profile.dist]
38+inherits = "release"
39+lto = "thin"
40+codegen-units = 16