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:
15 TARGET: x86_64-unknown-linux-musl15 TARGET: x86_64-unknown-linux-musl
16 # The systemd user unit that owns the process. See izlek.service.16 # The systemd user unit that owns the process. See izlek.service.
17 SERVICE: izlek17 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
18 25
19 jobs:26 jobs:
20 deploy:27 deploy:
@@ -37,10 +44,20 @@ jobs:
37 with:44 with:
38 cache-all-crates: true45 cache-all-crates: true
39 46
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+
40 - name: Install the topcoat CLI56 - name: Install the topcoat CLI
41 # Installed before the cargo config below exists, so the CLI itself is57 # Installed before the cargo config below exists, so the CLI itself is
42 # built for the host and not for musl.58 # built for the host and not for musl.
43- run: cargo install topcoat-cli@0.6.2 --locked59+ if: steps.topcoat-cache.outputs.cache-hit != 'true'
60+ run: cargo install topcoat-cli@${{ env.TOPCOAT }} --locked
44 61
45 - name: Point cargo at musl62 - name: Point cargo at musl
46 run: |63 run: |
@@ -60,12 +77,12 @@ jobs:
60 - name: Build the binary and bundle its assets77 - name: Build the binary and bundle its assets
61 run: |78 run: |
62 set -euo pipefail79 set -euo pipefail
63- # One compile: this builds izlek-web with the release profile and80+ # One compile: this builds izlek-web and writes out the asset bundle
64- # writes out the asset bundle embedded in the binary it produced.81+ # embedded in the binary it produced.
65- topcoat asset bundle --package izlek-web --release --out dist/assets82+ topcoat asset bundle --package izlek-web --profile "$PROFILE" --out stage/assets
66- cp "target/$TARGET/release/izlek-web" dist/izlek-web83+ cp "target/$TARGET/$PROFILE/izlek-web" stage/izlek-web
67- strip dist/izlek-web84+ strip stage/izlek-web
68- ls -l dist dist/assets85+ ls -l stage stage/assets
69 86
70 - name: Install SSH keys87 - name: Install SSH keys
71 run: |88 run: |
@@ -94,7 +111,7 @@ jobs:
94 rm -rf -- '${deploy_path}/current.new'111 rm -rf -- '${deploy_path}/current.new'
95 mkdir -p -- '${deploy_path}/current.new'112 mkdir -p -- '${deploy_path}/current.new'
96 "113 "
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'"
98 115
99 - name: Swap and restart116 - name: Swap and restart
100 run: |117 run: |
Cargo.tomlmodified+10 -0
@@ -28,3 +28,13 @@ toml = "1"
28 [profile.release]28 [profile.release]
29 codegen-units = 129 codegen-units = 1
30 lto = true30 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