The deploy builds thin, and the CLI is built once
Browse files at this commitecc25a3d6e46a70f119d9180600ad0368432a82aParent: 97e9050- perf
- the deploy builds thin, and the CLI is built once
2 changed files +35 -8
- .github/workflows/main.yml +25 -8
- Cargo.toml +10 -0
.github/workflows/main.ymlmodified+25 -8
| @@ -15,6 +15,13 @@ env: | ||
| 15 | 15 | TARGET: x86_64-unknown-linux-musl |
| 16 | 16 | # The systemd user unit that owns the process. See izlek.service. |
| 17 | 17 | 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 | 26 | jobs: |
| 20 | 27 | deploy: |
| @@ -37,10 +44,20 @@ jobs: | ||
| 37 | 44 | with: |
| 38 | 45 | 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 | 56 | - name: Install the topcoat CLI |
| 41 | 57 | # Installed before the cargo config below exists, so the CLI itself is |
| 42 | 58 | # 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 | |
| 44 | 61 | |
| 45 | 62 | - name: Point cargo at musl |
| 46 | 63 | run: | |
| @@ -60,12 +77,12 @@ jobs: | ||
| 60 | 77 | - name: Build the binary and bundle its assets |
| 61 | 78 | run: | |
| 62 | 79 | 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 | |
| 69 | 86 | |
| 70 | 87 | - name: Install SSH keys |
| 71 | 88 | run: | |
| @@ -94,7 +111,7 @@ jobs: | ||
| 94 | 111 | rm -rf -- '${deploy_path}/current.new' |
| 95 | 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 | 116 | - name: Swap and restart |
| 100 | 117 | run: | |
Cargo.tomlmodified+10 -0
| @@ -28,3 +28,13 @@ toml = "1" | ||
| 28 | 28 | [profile.release] |
| 29 | 29 | codegen-units = 1 |
| 30 | 30 | 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 |