[pr-performance] Parallel ThinLTO release profile, isolate DARNER_BUILD git rebuilds, and fix Rust 1.98.1 clippy lint #130

Open
davetheshrew wants to merge 1 commit from davetheshrew/Darner:pr/build-optimise into main
Contributor

Contributor role (optional)

  • Fluxer ID: 1577790829722873856

What it changes

  1. Parallel ThinLTO default release profile (Cargo.toml, scripts/pgo.ps1)
    • Switched [profile.release] from lto = "fat" / codegen-units = 1 to lto = "thin" / codegen-units = 16 (retaining debug = "line-tables-only") so release builds parallelize across cores instead of bottlenecking on a single-threaded final LTO step.
    • Added [profile.dist] (inherits = "release", lto = "fat", codegen-units = 1) for distribution builds where build time does not matter, and added -Profile release|dist to scripts/pgo.ps1.
  2. Isolate DARNER_BUILD git watches to the binary crate (apps/darner/build.rs, crates/darner-gpu/build.rs, crates/darner-gpu/src/start_notice.rs, apps/darner/src/main.rs, apps/darner/src/play.rs, crates/darner-gpu/src/host.rs, crates/darner-gpu/src/host/panel.rs)
    • Previously crates/darner-gpu/build.rs computed DARNER_BUILD and emitted cargo:rerun-if-changed on .git/HEAD, .git/logs/HEAD, .git/packed-refs, and .git/refs/tags, causing every git commit, branch switch, or reflog update to invalidate and rebuild darner-gpu and downstream darner-hle.
    • Moved DARNER_BUILD computation into apps/darner/build.rs, watching only build.rs, DARNER_BUILD_NAME, existing HEAD/packed-refs/refs/tags, and the active symbolic-ref branch file (without .git/logs/HEAD).
    • Replaced darner_hle::start_notice::BUILD with OnceLock-backed set_build / build(), initialized at startup in apps/darner/src/main.rs, and read env!("DARNER_BUILD") directly inside apps/darner/src/play.rs.
  3. Track locale JSON changes explicitly (crates/darner-core/build.rs)
    • Added cargo:rerun-if-changed=build.rs and per-file cargo:rerun-if-changed directives for ../../locales/*.json.
  4. Rust 1.98.1 Clippy fix (crates/darner-gpu/src/host.rs)
    • Replaced (n % 2 == 0).then_some(n) in made_once_tests with n.is_multiple_of(2).then_some(n) for clippy::manual_is_multiple_of.

How it was tested

  • Tested revision: ecfb0ab (rebased onto upstream/main 57dea7f)
  • Commands and results:
    • git diff --stat upstream/main...HEAD: 10 files changed, 96 insertions, 61 deletions (Cargo.toml, apps/darner/build.rs, apps/darner/src/main.rs, apps/darner/src/play.rs, crates/darner-core/build.rs, crates/darner-gpu/build.rs, crates/darner-gpu/src/host.rs, crates/darner-gpu/src/host/panel.rs, crates/darner-gpu/src/start_notice.rs, scripts/pgo.ps1).
    • Verified line endings: all modified .rs/.toml files use LF (0 CRLF); scripts/pgo.ps1 preserves CRLF (84 CRLF, 0 bare LF).
    • Checked all 51 open PRs on TrustNo1/Darner via the Forgejo API for build-script, profile, or Clippy 1.98.1 overlap.
  • Coverage gaps:
    • No Rust/Windows toolchain is installed in this workspace container, so cargo clippy --workspace --all-targets --locked -- -D warnings, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --locked, cargo xtask policy --staged, and live Windows build-time comparisons still need to be run on Windows before merging.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found addressing Cargo LTO profiles, DARNER_BUILD rebuild isolation, locales/*.json rebuild tracking, or Clippy manual_is_multiple_of (unrelated open PRs also touch host.rs, panel.rs, main.rs, or play.rs: #34, #36, #47, #48, #50, #57, #58, #59, #62, #75, #80, #93).
<!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> <!-- Use Fixes #N for a complete fix or Refs #N for a partial change. --> ## Contributor role (optional) - Fluxer ID: 1577790829722873856 ## What it changes 1. **Parallel ThinLTO default release profile (`Cargo.toml`, `scripts/pgo.ps1`)** - Switched `[profile.release]` from `lto = "fat"` / `codegen-units = 1` to `lto = "thin"` / `codegen-units = 16` (retaining `debug = "line-tables-only"`) so release builds parallelize across cores instead of bottlenecking on a single-threaded final LTO step. - Added `[profile.dist]` (`inherits = "release"`, `lto = "fat"`, `codegen-units = 1`) for distribution builds where build time does not matter, and added `-Profile release|dist` to `scripts/pgo.ps1`. 2. **Isolate `DARNER_BUILD` git watches to the binary crate (`apps/darner/build.rs`, `crates/darner-gpu/build.rs`, `crates/darner-gpu/src/start_notice.rs`, `apps/darner/src/main.rs`, `apps/darner/src/play.rs`, `crates/darner-gpu/src/host.rs`, `crates/darner-gpu/src/host/panel.rs`)** - Previously `crates/darner-gpu/build.rs` computed `DARNER_BUILD` and emitted `cargo:rerun-if-changed` on `.git/HEAD`, `.git/logs/HEAD`, `.git/packed-refs`, and `.git/refs/tags`, causing every git commit, branch switch, or reflog update to invalidate and rebuild `darner-gpu` and downstream `darner-hle`. - Moved `DARNER_BUILD` computation into `apps/darner/build.rs`, watching only `build.rs`, `DARNER_BUILD_NAME`, existing `HEAD`/`packed-refs`/`refs/tags`, and the active `symbolic-ref` branch file (without `.git/logs/HEAD`). - Replaced `darner_hle::start_notice::BUILD` with `OnceLock`-backed `set_build` / `build()`, initialized at startup in `apps/darner/src/main.rs`, and read `env!("DARNER_BUILD")` directly inside `apps/darner/src/play.rs`. 3. **Track locale JSON changes explicitly (`crates/darner-core/build.rs`)** - Added `cargo:rerun-if-changed=build.rs` and per-file `cargo:rerun-if-changed` directives for `../../locales/*.json`. 4. **Rust 1.98.1 Clippy fix (`crates/darner-gpu/src/host.rs`)** - Replaced `(n % 2 == 0).then_some(n)` in `made_once_tests` with `n.is_multiple_of(2).then_some(n)` for `clippy::manual_is_multiple_of`. ## How it was tested - Tested revision: `ecfb0ab` (rebased onto `upstream/main` `57dea7f`) - Commands and results: - `git diff --stat upstream/main...HEAD`: 10 files changed, 96 insertions, 61 deletions (`Cargo.toml`, `apps/darner/build.rs`, `apps/darner/src/main.rs`, `apps/darner/src/play.rs`, `crates/darner-core/build.rs`, `crates/darner-gpu/build.rs`, `crates/darner-gpu/src/host.rs`, `crates/darner-gpu/src/host/panel.rs`, `crates/darner-gpu/src/start_notice.rs`, `scripts/pgo.ps1`). - Verified line endings: all modified `.rs`/`.toml` files use LF (`0` CRLF); `scripts/pgo.ps1` preserves CRLF (`84` CRLF, `0` bare LF). - Checked all 51 open PRs on `TrustNo1/Darner` via the Forgejo API for build-script, profile, or Clippy 1.98.1 overlap. - Coverage gaps: - No Rust/Windows toolchain is installed in this workspace container, so `cargo clippy --workspace --all-targets --locked -- -D warnings`, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, `cargo test --workspace --locked`, `cargo xtask policy --staged`, and live Windows build-time comparisons still need to be run on Windows before merging. ## Checklist - [x] This PR contains one change based on `main`. - [ ] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found addressing Cargo LTO profiles, `DARNER_BUILD` rebuild isolation, `locales/*.json` rebuild tracking, or Clippy `manual_is_multiple_of` (unrelated open PRs also touch `host.rs`, `panel.rs`, `main.rs`, or `play.rs`: #34, #36, #47, #48, #50, #57, #58, #59, #62, #75, #80, #93).
Owner

Before this can be merged, it needs a runtime measurement. The published exe is built with cargo build --release, so this PR turns it from one fat-LTO unit into ThinLTO with 16 codegen units. The frame here is limited by the processor, and the old profile comment says the hot paths cross crates. A slower exe would ship without anyone noticing.

Please add an A/B in the game: the current release profile against this PR's release. Same save, same spot, pipelines warm, at least two runs each, alternated. Give the per-run fps (median of the 5 s lines) and the CPU and card. If ThinLTO is slower, the release profile should stay fat and the faster build should go in a new profile instead.

The other two changes (the DARNER_BUILD rebuild isolation and the clippy lint) can be merged on their own. Please split them into a separate PR.

Before this can be merged, it needs a runtime measurement. The published exe is built with `cargo build --release`, so this PR turns it from one fat-LTO unit into ThinLTO with 16 codegen units. The frame here is limited by the processor, and the old profile comment says the hot paths cross crates. A slower exe would ship without anyone noticing. Please add an A/B in the game: the current `release` profile against this PR's `release`. Same save, same spot, pipelines warm, at least two runs each, alternated. Give the per-run fps (median of the 5 s lines) and the CPU and card. If ThinLTO is slower, the release profile should stay fat and the faster build should go in a new profile instead. The other two changes (the `DARNER_BUILD` rebuild isolation and the clippy lint) can be merged on their own. Please split them into a separate PR.
First-time contributor

Note from me: I did not test this PR but in my use of ThinLTO, the full tree was rebuilt in 77 s versus about 4 minutes for fat LTO on my workstation. So there is a possible gain here for testing builds.

Note from me: I did not test this PR but in my use of ThinLTO, the full tree was rebuilt in 77 s versus about 4 minutes for fat LTO on my workstation. So there is a possible gain here for testing builds.
Contributor

The (default) fast build profile is for this. It does make a noticable speed difference. It should not be the default for release. The release build does a full optimization, and it is needed.

The (default) fast build profile is for this. It does make a noticable speed difference. It should not be the default for release. The release build does a full optimization, and it is needed.
Contributor

See the "Fast and release builds" section in README.md

See the "Fast and release builds" section in README.md
First-time contributor

I compared CPU texture decoding on the two release profiles. The timing ranges overlapped on every format. The requested in-game FPS comparison remains open.

Main was 57dea7f236 (fat LTO, one codegen unit), candidate ecfb0ab085 (ThinLTO, 16 units). Median [min–max] in ns per block across four scored processes per build:

Format Main PR
BC1 296.70 [273.3–352.5] 293.20 [249.2–315.0]
BC3 556.85 [535.8–644.8] 547.50 [522.0–638.9]
BC4 272.15 [267.9–275.3] 265.00 [261.4–273.2]
BC5 539.80 [522.2–561.9] 532.90 [526.7–588.0]
BC6 859.35 [839.2–876.4] 800.90 [794.6–881.1]
BC7 847.25 [807.2–907.1] 862.15 [802.0–1005.7]

Windows 11, i5-13600KF, Rust 1.98.1 MSVC. Both clean trees used the same lockfile. I built with cargo test --release --no-run --locked --offline --jobs 1 -p darner-formats and ran bcpack::tests::bcpack_throughput_builtin --exact --ignored --nocapture --test-threads=1 on logical CPU 19. Each sample decoded 16,384 fixed blocks 40 times. One unscored warm-up per arm, then A/B/B/A and B/A/A/B in fresh processes. All four decoder oracle tests passed on each build. Both full release executables also built successfully.

Separate finding for the build-label change. With the unchanged PR build script and icon in a small Cargo fixture, I packed the checked-out branch with git pack-refs --all, ran cargo check --locked --offline, made an empty commit, and ran the same check again. HEAD advanced from 32388574 to d9a5da57, but the script still exported 32388574. The loose-branch control updated correctly. The build-label fix watches the nearest existing parent until Git creates the loose ref. I verified the reported revision before and after the next commit on loose, packed, nested packed, reflog-disabled packed, and detached checkouts. The timing runs above used the original PR.

I compared CPU texture decoding on the two release profiles. The timing ranges overlapped on every format. The requested in-game FPS comparison remains open. Main was `57dea7f236` (fat LTO, one codegen unit), candidate `ecfb0ab085` (ThinLTO, 16 units). Median [min–max] in ns per block across four scored processes per build: | Format | Main | PR | |---|---:|---:| | BC1 | 296.70 [273.3–352.5] | 293.20 [249.2–315.0] | | BC3 | 556.85 [535.8–644.8] | 547.50 [522.0–638.9] | | BC4 | 272.15 [267.9–275.3] | 265.00 [261.4–273.2] | | BC5 | 539.80 [522.2–561.9] | 532.90 [526.7–588.0] | | BC6 | 859.35 [839.2–876.4] | 800.90 [794.6–881.1] | | BC7 | 847.25 [807.2–907.1] | 862.15 [802.0–1005.7] | Windows 11, i5-13600KF, Rust 1.98.1 MSVC. Both clean trees used the same lockfile. I built with `cargo test --release --no-run --locked --offline --jobs 1 -p darner-formats` and ran `bcpack::tests::bcpack_throughput_builtin --exact --ignored --nocapture --test-threads=1` on logical CPU 19. Each sample decoded 16,384 fixed blocks 40 times. One unscored warm-up per arm, then A/B/B/A and B/A/A/B in fresh processes. All four decoder oracle tests passed on each build. Both full release executables also built successfully. **Separate finding for the build-label change.** With the unchanged PR build script and icon in a small Cargo fixture, I packed the checked-out branch with `git pack-refs --all`, ran `cargo check --locked --offline`, made an empty commit, and ran the same check again. HEAD advanced from `32388574` to `d9a5da57`, but the script still exported `32388574`. The loose-branch control updated correctly. The [build-label fix](https://git.gtahub.st/attachments/97672dbd-1e00-4ae1-9841-d3f17f94a15c) watches the nearest existing parent until Git creates the loose ref. I verified the reported revision before and after the next commit on loose, packed, nested packed, reflog-disabled packed, and detached checkouts. The timing runs above used the original PR.
First-time contributor

Built and tested #130 on Windows (Ryzen 7 9800X3D, RTX 5080, Rust 1.98.1): a clean cargo build --release --locked -p darner succeeds in 1m48s with -C lto=thin -C codegen-units=16, a second build is a no-op (0.12s), and after an empty commit only darner recompiled while DARNER_BUILD went from v2026.12.03.01-23 to -24; DARNER_BUILD_NAME behaves the same and lands in the exe.

Gate 1 is red as pushed: cargo clippy -p darner-gpu -p darner --all-targets -- -D warnings fails with E0689 at crates/darner-gpu/src/host.rs:13171 (test racing_callers_all_get_the_value_published_first): n.is_multiple_of(2) on an ambiguous {integer}. Annotating .map(|n: usize| ...) makes it pass (exit 0), so it's a one-line fix. Lib-only clippy passes either way.

The dist profile compiles with -C codegen-units=1 -C linker-plugin-lto (probe build of darner-core at that profile); I did not run the Fat LTO link itself.

In game at Jason's house, standing still for 3 minutes per arm (one run each): ThinLTO median 32.6 fps / 30.9 ms vs main 29.8 fps / 33.6 ms (ranges 28.4-35.8 vs 26.6-34.8; draw counts differed, 6681 vs 7856, so indicative only). No regression seen.

Drafted with AI assistance (OpenCode).

Built and tested #130 on Windows (Ryzen 7 9800X3D, RTX 5080, Rust 1.98.1): a clean `cargo build --release --locked -p darner` succeeds in 1m48s with `-C lto=thin -C codegen-units=16`, a second build is a no-op (0.12s), and after an empty commit only `darner` recompiled while DARNER_BUILD went from v2026.12.03.01-23 to -24; DARNER_BUILD_NAME behaves the same and lands in the exe. Gate 1 is red as pushed: `cargo clippy -p darner-gpu -p darner --all-targets -- -D warnings` fails with E0689 at crates/darner-gpu/src/host.rs:13171 (test racing_callers_all_get_the_value_published_first): `n.is_multiple_of(2)` on an ambiguous `{integer}`. Annotating `.map(|n: usize| ...)` makes it pass (exit 0), so it's a one-line fix. Lib-only clippy passes either way. The dist profile compiles with `-C codegen-units=1 -C linker-plugin-lto` (probe build of darner-core at that profile); I did not run the Fat LTO link itself. In game at Jason's house, standing still for 3 minutes per arm (one run each): ThinLTO median 32.6 fps / 30.9 ms vs main 29.8 fps / 33.6 ms (ranges 28.4-35.8 vs 26.6-34.8; draw counts differed, 6681 vs 7856, so indicative only). No regression seen. Drafted with AI assistance (OpenCode).
First-time contributor

I ran the requested release-profile comparison on an i5-13600KF and RTX 4070 Ti SUPER 16 GB (Windows 11, NVIDIA 617.14). Both runs of the PR had higher median FPS than the preceding baseline, but also fewer draw calls per frame. The GPU was at 99% utilization in all four windows. I can't attribute the difference to ThinLTO from this scene.

A is the direct parent 57dea7f236 (fat LTO, 1 codegen unit). B is the PR head ecfb0ab085 (ThinLTO, 16 units). Both were built with Rust 1.98.1 using the same locked dependencies. Native 2560×1440, Series X profile, upscaling, frame generation and RT off. The title and Darner frame caps were lifted for all four measured windows.

Run order Median printed FPS (samples) Rendered FPS over window p99 frame time Median draws/frame
A1 · parent 23.7 (17) 23.63 72.67 ms 6,511
B1 · PR 25.5 (18) 25.13 66.67 ms 5,952
A2 · parent 23.5 (17) 23.70 75.85 ms 6,420
B2 · PR 23.9 (17) 23.95 74.39 ms 6,264.5

I warmed each build once before scoring, kept separate caches, then ran A/B/A/B. Each launch used a fresh copy of the same save files and settings. I checked the view before and after each window. The character stayed beside the same pickup facing the same storefront, with no movement input. Nearby vehicles varied between launches. Each window ran from 60 to 150 seconds after the first world-frame marker. The primary column is the per-run median of Darner's printed FPS lines. The next two columns use complete present intervals within the same window.

The paired differences were +1.8 and +0.4 FPS, with 8.6% and 2.4% fewer draw calls on the PR, respectively. NVIDIA utilization was 99% at the median and peak in each run (45 samples per window). All four warmed runs still created some pipelines (11 / 8 / 5 / 7 in order). The largest accumulated pipeline wait was 1.14 s in B1. These runs give a native-1440p result for this card. A comparison in a CPU-limited scene with a repeatable workload would better isolate the release-profile change.

I ran the requested release-profile comparison on an i5-13600KF and RTX 4070 Ti SUPER 16 GB (Windows 11, NVIDIA 617.14). Both runs of the PR had higher median FPS than the preceding baseline, but also fewer draw calls per frame. The GPU was at 99% utilization in all four windows. I can't attribute the difference to ThinLTO from this scene. A is the direct parent `57dea7f236` (fat LTO, 1 codegen unit). B is the PR head `ecfb0ab085` (ThinLTO, 16 units). Both were built with Rust 1.98.1 using the same locked dependencies. Native 2560×1440, Series X profile, upscaling, frame generation and RT off. The title and Darner frame caps were lifted for all four measured windows. | Run order | Median printed FPS (samples) | Rendered FPS over window | p99 frame time | Median draws/frame | |---|---:|---:|---:|---:| | A1 · parent | 23.7 (17) | 23.63 | 72.67 ms | 6,511 | | B1 · PR | 25.5 (18) | 25.13 | 66.67 ms | 5,952 | | A2 · parent | 23.5 (17) | 23.70 | 75.85 ms | 6,420 | | B2 · PR | 23.9 (17) | 23.95 | 74.39 ms | 6,264.5 | I warmed each build once before scoring, kept separate caches, then ran A/B/A/B. Each launch used a fresh copy of the same save files and settings. I checked the view before and after each window. The character stayed beside the same pickup facing the same storefront, with no movement input. Nearby vehicles varied between launches. Each window ran from 60 to 150 seconds after the first world-frame marker. The primary column is the per-run median of Darner's printed FPS lines. The next two columns use complete present intervals within the same window. The paired differences were +1.8 and +0.4 FPS, with 8.6% and 2.4% fewer draw calls on the PR, respectively. NVIDIA utilization was 99% at the median and peak in each run (45 samples per window). All four warmed runs still created some pipelines (11 / 8 / 5 / 7 in order). The largest accumulated pipeline wait was 1.14 s in B1. These runs give a native-1440p result for this card. A comparison in a CPU-limited scene with a repeatable workload would better isolate the release-profile change.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/build-optimise:davetheshrew-pr/build-optimise'
git switch 'davetheshrew-pr/build-optimise'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'davetheshrew-pr/build-optimise'
git switch 'davetheshrew-pr/build-optimise'
git rebase 'main'
git switch 'main'
git merge --ff-only 'davetheshrew-pr/build-optimise'
git switch 'davetheshrew-pr/build-optimise'
git rebase 'main'
git switch 'main'
git merge --no-ff 'davetheshrew-pr/build-optimise'
git switch 'main'
git merge --squash 'davetheshrew-pr/build-optimise'
git switch 'main'
git merge --ff-only 'davetheshrew-pr/build-optimise'
git switch 'main'
git merge 'davetheshrew-pr/build-optimise'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!130
No description provided.