From 9e235a7c51c7ba1737a8fe232b9c364215ad002d Mon Sep 17 00:00:00 2001 From: Geoffrey Vancoetsem <10533139+geeooff@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:19:13 +0100 Subject: [PATCH 1/2] Add a release-fast profile for local builds and pull request CI Fat LTO with one codegen unit runs on a single thread (1 min 43 s after each commit on a 16-core CPU); thin LTO with 16 units takes 22 s for an exe about 12 % larger. build.ps1 build and pull request CI (release -Fast) use it; tags and main's CI keep the published fat LTO profile. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 6 ++++-- AGENTS.md | 7 ++++++- CONTRIBUTING.md | 2 +- Cargo.toml | 8 ++++++++ docs/architecture.md | 12 ++++++++++++ scripts/build.ps1 | 32 ++++++++++++++++++++++---------- 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89e9f97..4a391b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,10 +61,12 @@ jobs: # The same checklist a developer runs: fmt, clippy -D warnings, rustdoc -D warnings, tests, # documentation links, no video or personal path tracked, then the release executable (with its # commit and third-party notices inside) and its checksum. One script, so CI and a developer's - # machine cannot drift apart. + # machine cannot drift apart. A pull request builds it with the release-fast profile (thin LTO on + # every core, minutes faster); main, after each merge, with the published fat LTO profile, so the + # profile a tag uses is built on every change before any release. - name: Test and build the release executable shell: pwsh - run: .\scripts\build.ps1 release + run: .\scripts\build.ps1 release ${{ github.event_name == 'pull_request' && '-Fast' || '' }} - name: Read the version id: version diff --git a/AGENTS.md b/AGENTS.md index 3c9d5be..1696d1d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -69,10 +69,15 @@ tests/pipeline.rs end to end on synthetic clips examples/transcode.rs ```powershell .\scripts\build.ps1 # fmt, clippy -D warnings, rustdoc -D warnings, tests, doc links, no video / personal path -.\scripts\build.ps1 build # + release build +.\scripts\build.ps1 build # + optimized build, release-fast profile (thin LTO, ~20 s) .\scripts\build.ps1 release # + clean tree, notices, the .exe, SHA256SUMS.txt and notes.md in dist\ (needs cargo-about) ``` +- **Two optimized profiles.** `release` (fat LTO, one codegen unit: the smallest, best-optimized exe, + but one thread, ~1 min 45 s) is what users get: tags, main's CI. `release-fast` (thin LTO, 16 units, + ~20 s, exe ~12 % larger) is for checks: `build.ps1 build` and pull request CI (`release -Fast`). Never + publish a `-Fast` build. Measured 2026-11-23 on a Ryzen 9 9950X3D: fat LTO cannot use more threads. + - **One file.** A release is `quick-video-transcoder.exe` alone: static C runtime, icon, third-party notices (`--licenses`, *About*) inside. FFmpeg stays outside, found on the `PATH` or installed with winget on the user's request. Keep it that way: nothing a user must unpack or install beside it. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0fdd6db..d84e793 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ FFmpeg on the `PATH` for the end-to-end test. Before committing, run the same ch ```powershell .\scripts\build.ps1 # fmt, clippy, rustdoc, tests, doc links, no video or personal path tracked -.\scripts\build.ps1 build # the same, then a release build +.\scripts\build.ps1 build # the same, then an optimized build (release-fast profile: thin LTO, about 20 s) .\scripts\build.ps1 release # from a clean tree: the same, then the release .exe and its checksum in dist\ ``` diff --git a/Cargo.toml b/Cargo.toml index aa590e1..999b156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,14 @@ codegen-units = 1 strip = "symbols" # Panics keep unwinding: a worker thread that fails must not take the window down. +# For checks, not for users: local builds and pull request CI. Fat LTO runs on one thread (1 min 43 s on +# a 16-core CPU after each commit); thin LTO spreads over the cores (22 s), for an executable about 12 % +# larger. Published releases always use `release` (scripts/build.ps1 release without -Fast). +[profile.release-fast] +inherits = "release" +lto = "thin" +codegen-units = 16 + [lints.rust] missing_docs = "warn" unsafe_code = "forbid" diff --git a/docs/architecture.md b/docs/architecture.md index 6e7dbd9..ad5bde3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -146,6 +146,18 @@ statically (`.cargo/config.toml`). The script then asks the built executable for notices, and writes the executable, `SHA256SUMS.txt` and `notes.md` (the changelog section) to `dist\`. `release.yml` runs it on a `v*` tag, requires `notes.md`, attests `SHA256SUMS.txt` and publishes. +Build time (Ryzen 9 9950X3D, 16 cores, rustc 1.98, 2026-11-23, after a commit, dependencies cached): + +| Profile | Final step | Exe | +| --- | --- | --- | +| `release`: fat LTO, 1 codegen unit (published) | 1 min 43 s | 18.7 MB | +| fat LTO, 16 codegen units | 2 min 09 s | 19.5 MB | +| `release-fast`: thin LTO, 16 codegen units (checks) | 22 s | 21.0 MB | + +Fat LTO merges the whole program and its dependencies into one LLVM module optimized on one thread; more +codegen units only make the merge slower, and a faster linker (`rust-lld`) saves under a second. So the +published profile stays fat, and checks (`build.ps1 build`, pull request CI) use `release-fast`. + When FFmpeg is missing and winget runs, the *FFmpeg is needed* window offers to run `winget install --id Gyan.FFmpeg --exact --silent` with the package and source agreements accepted (the window says so), then checks again with the `PATH` re-read. diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 9f604f3..9d0d000 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -4,15 +4,21 @@ # drift apart. # # .\scripts\build.ps1 # test (the default) -# .\scripts\build.ps1 build # test, then the release build -# .\scripts\build.ps1 release # test, notices, release build, the .exe and its checksum in dist\ (from a clean tree outside CI) +# .\scripts\build.ps1 build # test, then an optimized build with the release-fast profile (thin LTO) +# .\scripts\build.ps1 release # test, notices, the published build (fat LTO), the .exe and its checksum in dist\ +# .\scripts\build.ps1 release -Fast # the same with release-fast: pull request CI +# +# A release is built from a clean tree outside CI, always without -Fast. # # Never pipe it into Select-Object -First: that stops the pipeline mid-run, and a truncated run can look # like a success. Read the whole output, or the last line. param( [ValidateSet('test', 'build', 'release')] - [string] $Task = 'test' + [string] $Task = 'test', + # release only: build with the release-fast profile (thin LTO, every core) instead of the published + # one. For pull request CI, which checks the packaging without the minutes of a fat LTO. + [switch] $Fast ) $ErrorActionPreference = 'Stop' @@ -157,7 +163,7 @@ function Invoke-Tests { # A release build embeds the third-party notices: generated here by cargo-about into target\, handed to # build.rs through QVT_NOTICES. A plain build embeds a placeholder. -function Invoke-Build([switch] $WithNotices) { +function Invoke-Build([string] $CargoProfile, [switch] $WithNotices) { if ($WithNotices) { Step "Third-party notices" if (-not (Get-Command cargo-about -ErrorAction SilentlyContinue)) { @@ -169,8 +175,8 @@ function Invoke-Build([switch] $WithNotices) { Write-Host " $([math]::Round((Get-Item $notices).Length / 1KB)) KB" $env:QVT_NOTICES = $notices } - Step "Release build" - try { Run 'cargo' @('build', '--release', '--locked') } finally { Remove-Item Env:\QVT_NOTICES -ErrorAction SilentlyContinue } + Step "Optimized build ($CargoProfile profile)" + try { Run 'cargo' @('build', '--profile', $CargoProfile, '--locked') } finally { Remove-Item Env:\QVT_NOTICES -ErrorAction SilentlyContinue } } # Starts the built executable with one argument and returns what it printed. A windowed program: @@ -202,10 +208,10 @@ function Assert-CleanTree { # documentation inside (About, --licenses, --version). Its name carries no version, so replacing the file # updates it and the Send to shortcut keeps working. Next to it in dist\: SHA256SUMS.txt, and notes.md # (the changelog section) when the version has a dated one. -function Invoke-Package { +function Invoke-Package([string] $CargoProfile) { $version = Get-Version $dist = Join-Path $root 'dist' - $exe = Join-Path $root 'target\release\quick-video-transcoder.exe' + $exe = Join-Path $root "target\$CargoProfile\quick-video-transcoder.exe" # Asked of the executable rather than of git: it is what users run. Step "The executable names its commit and carries its notices" @@ -243,7 +249,13 @@ function Invoke-Package { if ($Task -eq 'release') { Assert-CleanTree } Invoke-Tests -if ($Task -eq 'build') { Invoke-Build } -if ($Task -eq 'release') { Invoke-Build -WithNotices; Invoke-Package } +if ($Fast -and $Task -ne 'release') { Fail "-Fast only applies to the release task" } +if ($Task -eq 'build') { Invoke-Build 'release-fast' } +if ($Task -eq 'release') { + $cargoProfile = if ($Fast) { 'release-fast' } else { 'release' } + Invoke-Build $cargoProfile -WithNotices + Invoke-Package $cargoProfile + if ($Fast) { Write-Host " built with release-fast: a check, not an executable to publish" -ForegroundColor Yellow } +} Write-Host "" Write-Host "$Task OK" -ForegroundColor Green From e35f7eceaf2f89d4ae7b945ca51d4b8be6e56554 Mon Sep 17 00:00:00 2001 From: Geoffrey Vancoetsem <10533139+geeooff@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:30:01 +0100 Subject: [PATCH 2/2] Warm the CI cache with release-fast dependencies on main Pull requests restore main's cache on an exact key match and never save their own, so their release-fast dependencies were rebuilt every time. Main now builds them too after the release build. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 8 ++++++++ AGENTS.md | 2 ++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a391b2..90c90db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,14 @@ jobs: shell: pwsh run: .\scripts\build.ps1 release ${{ github.event_name == 'pull_request' && '-Fast' || '' }} + # Pull requests can read main's cache but never write their own when the key matches exactly (same + # Cargo.lock), and release-fast compiles its dependencies with other settings than release. So main + # compiles them too, into the cache it saves: pull requests then only rebuild the application. + - name: Warm the cache for pull requests (release-fast dependencies) + if: github.event_name != 'pull_request' + shell: pwsh + run: cargo build --profile release-fast --locked + - name: Read the version id: version shell: pwsh diff --git a/AGENTS.md b/AGENTS.md index 1696d1d..b646b6f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,6 +77,8 @@ tests/pipeline.rs end to end on synthetic clips examples/transcode.rs but one thread, ~1 min 45 s) is what users get: tags, main's CI. `release-fast` (thin LTO, 16 units, ~20 s, exe ~12 % larger) is for checks: `build.ps1 build` and pull request CI (`release -Fast`). Never publish a `-Fast` build. Measured 2026-11-23 on a Ryzen 9 9950X3D: fat LTO cannot use more threads. + CI caches are scoped: a pull request reads main's cache and never saves its own on an exact key match, + so main's CI also builds `release-fast`, only to put its dependencies in the cache. - **One file.** A release is `quick-video-transcoder.exe` alone: static C runtime, icon, third-party notices (`--licenses`, *About*) inside. FFmpeg stays outside, found on the `PATH` or installed with