WIP: [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) #142

Draft
Jesper-A wants to merge 1 commit from Jesper-A/Darner:up-preload-skip into main
Contributor

Refs #128

Contributor role (optional)

  • Fluxer ID: none given

What it changes

New switch DARNER_PRECOMPILE_SKIP_DONE=1, off by default. With it off, nothing changes.

Part of #128: a preload that starts again redoes the shader step from the start, even with every shader already stored. Most of that step goes on reading and scanning the title files, not on translating.

With the switch on:

  • When the shader step finishes a title file, it adds one line to <cache>/shaders/precompiled.txt: size, modification time, path.
  • On the next run, a file whose size and modification time match its line is skipped. It is not read or scanned.
  • The first line of the list is a key from the new shader_cache::build_key(): the translator hash, the switches that change what a translation looks like, and the host limits. A list made under another key is thrown away.
  • The list lives in shaders/. clear_stale_in deletes that folder when the translator changes, so the list goes with the translations. DARNER_KEEP_OLD_SHADERS and named caches are covered by the key.
  • A line is added as soon as its file is done, so a stopped preload keeps the files it finished.

Caveats:

  • For a skipped file, the earlier run's "do not translate" lines are not listed again. The list says the file was finished, not that every shader in it translated.
  • A skipped file's shaders are not counted, so the closing "N shaders in the cache" line and the progress counts cover only this run's files.
  • With the switch on, build_key brings up the host (the view-limit probe), which costs some time. Not measured.

It does not help the cold translation after a translator change (about 2 minutes here). That is a different step of #128: keeping work across translator changes, as blazecoding2009 noted in the issue.

New public functions, additive only: darner_gpu::shader_cache::build_key and darner_hle::modules::d3d12x::shader_build_key. Also a README row and a short entry in docs/findings.md.

Why this is expected to help (from earlier logs of ours, switch not on): a warm-cache shader step took about 24 s for 25,770 shaders. About 17 s of that came before the first progress line, while the files before the first one holding shaders were read and scanned. The lookups took about 0.25 ms each.

So the saving is an estimate, up to about 17 s per start on this PC. It is an upper bound: the 17 s also covers the directory walk and the first 1000 lookups, and the walk still runs with the switch on. The old logs came from our own branch builds, not from this commit, and their GPU clocks were in an unknown state (the step is mostly disk and CPU). Nothing is measured with the switch on.

Spec dependence

Likely general: the code is in the launcher's preload and does not depend on the GPU. How much is saved depends on how fast the disk reads the title files. Our title drive is a SATA QLC drive, so a faster drive should save less. The numbers above are from an RTX 2070 SUPER 8 GB (Turing), driver 621.40, Resizable BAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, Series S + DLSS Performance; the timings come from runs with GPU clocks in an unknown state. Not checked on other PCs, Series X, or Linux/Proton.

How it was tested

  • Tested revision: 64729c78c (on top of trustno1/main 57dea7f23).
  • Commands and results:
    • cargo clippy --workspace --all-targets --locked -- -D warnings (gate 1): clean, at 64729c78c.
    • cargo xtask policy: ok.
    • cargo test -p darner --bin darner --locked translate::stamps: 5 of 5 passed. That is this module only, not the workspace tests.
    • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings) and gate 3 (cargo test --workspace --locked): not run, pending. This is why the PR is WIP.
  • Gameplay, when relevant: none. No game run with this change.
  • Before and after, when relevant: none. No timing with the switch on.
  • Shader wave sizes tested, when relevant: not relevant (no translation change).
  • Coverage gaps: no game run; no timing with the switch on; not run with a stopped preload or a real translator change; only the five unit tests of the list (a finished file is skipped, a changed file is read again, another key drops the list, a torn list is ignored line by line, identity is size plus a real time). There is no CI upstream, so none of this was checked by CI.

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 for the same change. PR #76 also touches apps/darner/src/translate.rs and crates/darner-gpu/src/shader_cache.rs, and PR #96 touches shader_cache.rs; neither does this. README.md is touched by #59, #75, #110 and #118 (a different table row each, so it may need a rebase). Related issue: #128 (this is its plan point 2); #125 is related to #128 too.

This change was made with AI assistance (Claude Code).

<!-- Refs #128 (partial: point 2 of the plan in the issue). Not a full fix. --> Refs #128 ## Contributor role (optional) - Fluxer ID: none given ## What it changes New switch `DARNER_PRECOMPILE_SKIP_DONE=1`, **off by default**. With it off, nothing changes. Part of #128: a preload that starts again redoes the shader step from the start, even with every shader already stored. Most of that step goes on reading and scanning the title files, not on translating. With the switch on: - When the shader step finishes a title file, it adds one line to `<cache>/shaders/precompiled.txt`: size, modification time, path. - On the next run, a file whose size and modification time match its line is skipped. It is not read or scanned. - The first line of the list is a key from the new `shader_cache::build_key()`: the translator hash, the switches that change what a translation looks like, and the host limits. A list made under another key is thrown away. - The list lives in `shaders/`. `clear_stale_in` deletes that folder when the translator changes, so the list goes with the translations. `DARNER_KEEP_OLD_SHADERS` and named caches are covered by the key. - A line is added as soon as its file is done, so a stopped preload keeps the files it finished. Caveats: - For a skipped file, the earlier run's "do not translate" lines are not listed again. The list says the file was finished, not that every shader in it translated. - A skipped file's shaders are not counted, so the closing "N shaders in the cache" line and the progress counts cover only this run's files. - With the switch on, `build_key` brings up the host (the view-limit probe), which costs some time. Not measured. It does **not** help the cold translation after a translator change (about 2 minutes here). That is a different step of #128: keeping work across translator changes, as blazecoding2009 noted in the issue. New public functions, additive only: `darner_gpu::shader_cache::build_key` and `darner_hle::modules::d3d12x::shader_build_key`. Also a README row and a short entry in `docs/findings.md`. Why this is expected to help (from earlier logs of ours, switch **not** on): a warm-cache shader step took about 24 s for 25,770 shaders. About 17 s of that came before the first progress line, while the files before the first one holding shaders were read and scanned. The lookups took about 0.25 ms each. So the saving is an **estimate**, up to about 17 s per start on this PC. It is an upper bound: the 17 s also covers the directory walk and the first 1000 lookups, and the walk still runs with the switch on. The old logs came from our own branch builds, not from this commit, and their GPU clocks were in an unknown state (the step is mostly disk and CPU). **Nothing is measured with the switch on.** ### Spec dependence Likely general: the code is in the launcher's preload and does not depend on the GPU. How much is saved depends on how fast the disk reads the title files. Our title drive is a SATA QLC drive, so a faster drive should save less. The numbers above are from an RTX 2070 SUPER 8 GB (Turing), driver 621.40, Resizable BAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, Series S + DLSS Performance; the timings come from runs with GPU clocks in an unknown state. Not checked on other PCs, Series X, or Linux/Proton. ## How it was tested - Tested revision: `64729c78c` (on top of `trustno1/main` `57dea7f23`). - Commands and results: - `cargo clippy --workspace --all-targets --locked -- -D warnings` (gate 1): clean, at `64729c78c`. - `cargo xtask policy`: ok. - `cargo test -p darner --bin darner --locked translate::stamps`: 5 of 5 passed. That is this module only, not the workspace tests. - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`) and gate 3 (`cargo test --workspace --locked`): **not run**, pending. This is why the PR is WIP. - Gameplay, when relevant: none. No game run with this change. - Before and after, when relevant: none. No timing with the switch on. - Shader wave sizes tested, when relevant: not relevant (no translation change). - Coverage gaps: no game run; no timing with the switch on; not run with a stopped preload or a real translator change; only the five unit tests of the list (a finished file is skipped, a changed file is read again, another key drops the list, a torn list is ignored line by line, identity is size plus a real time). There is no CI upstream, so none of this was checked by CI. ## Checklist - [x] This PR contains one change based on `main`. - [x] 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 for the same change. PR #76 also touches `apps/darner/src/translate.rs` and `crates/darner-gpu/src/shader_cache.rs`, and PR #96 touches `shader_cache.rs`; neither does this. README.md is touched by #59, #75, #110 and #118 (a different table row each, so it may need a rebase). Related issue: #128 (this is its plan point 2); #125 is related to #128 too. This change was made with AI assistance (Claude Code).
A restarted preload with every shader already stored still spends most of
its shader phase (about 17 of 24 s in warm logs) reading and scanning the
title files. With DARNER_PRECOMPILE_SKIP_DONE=1 (off by default), precompile
appends each finished file (size, modification time, path) to
shaders/precompiled.txt, under a key made of the translator, the switches
that shape a translation and the host (shader_cache::build_key), and skips
files whose line matches. A stopped preload keeps the files it finished; a
changed key discards the list, and clearing the shader cache clears it.

Refs #128

This change was made with AI assistance (Claude Code).
Jesper-A changed title from [pr-performance][startup][shaders] WIP: Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) to WIP: [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) 2026-12-03 23:04:58 +00:00
Jesper-A changed title from WIP: [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) to [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) 2026-12-04 00:20:17 +00:00
First-time contributor

Tested #142 on Windows (RTX 5080) against a GTA6 dump: build and 18 unit tests pass (5 stamps, 13 shader_cache). Bounded 180 s preloads: with DARNER_PRECOMPILE_SKIP_DONE=1 a restarted run reported '36 of 36 files skipped' and its shader phase took 0 s, versus 5 s re-reading everything with the switch off (warm cache). The 74 s first run is confounded: it populated the shared cache itself. No lock-wait lines seen, though the shader cache is shared with other builds here. Not tested: game run, full preload, pipeline warm phase, key invalidation.

Drafted with AI assistance (OpenCode).

Tested #142 on Windows (RTX 5080) against a GTA6 dump: build and 18 unit tests pass (5 stamps, 13 shader_cache). Bounded 180 s preloads: with `DARNER_PRECOMPILE_SKIP_DONE=1` a restarted run reported '36 of 36 files skipped' and its shader phase took 0 s, versus 5 s re-reading everything with the switch off (warm cache). The 74 s first run is confounded: it populated the shared cache itself. No lock-wait lines seen, though the shader cache is shared with other builds here. Not tested: game run, full preload, pipeline warm phase, key invalidation. Drafted with AI assistance (OpenCode).
Jesper-A changed title from [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) to WIP: [pr-performance][startup][shaders] Preload: skip title files whose shaders an earlier run finished (DARNER_PRECOMPILE_SKIP_DONE, off by default) 2026-12-04 02:24:40 +00:00
Owner

Second-opinion review: hold for now. The stamp list (shaders/precompiled.txt, keyed by build_key()) works for the bounded test, but three cases can leave shaders untranslated for good:

  1. A file is stamped done even when its translations failed or panicked (contain_panic), and nothing retries those shaders.
  2. With DARNER_SHADER_CACHE_DAYS, the prune deletes cache entries while the stamps stay, so the preload never translates those shaders again and they stutter in game. Clearing the list when a prune removes entries would fix it.
  3. Two preloads with different keyed switches on one shared cache folder: one rewrites the header, and the other then appends its files under the wrong key.
    A test of key invalidation and a full preload would be needed before merging. It conflicts with #184 (translate.rs) and #147/#140 (findings.md).
Second-opinion review: hold for now. The stamp list (`shaders/precompiled.txt`, keyed by `build_key()`) works for the bounded test, but three cases can leave shaders untranslated for good: 1. A file is stamped done even when its translations failed or panicked (`contain_panic`), and nothing retries those shaders. 2. With `DARNER_SHADER_CACHE_DAYS`, the prune deletes cache entries while the stamps stay, so the preload never translates those shaders again and they stutter in game. Clearing the list when a prune removes entries would fix it. 3. Two preloads with different keyed switches on one shared cache folder: one rewrites the header, and the other then appends its files under the wrong key. A test of key invalidation and a full preload would be needed before merging. It conflicts with #184 (translate.rs) and #147/#140 (findings.md).
This pull request has changes conflicting with the target branch.
  • apps/darner/src/translate.rs
  • docs/findings.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'up-preload-skip:Jesper-A-up-preload-skip'
git switch 'Jesper-A-up-preload-skip'

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 'Jesper-A-up-preload-skip'
git switch 'Jesper-A-up-preload-skip'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Jesper-A-up-preload-skip'
git switch 'Jesper-A-up-preload-skip'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Jesper-A-up-preload-skip'
git switch 'main'
git merge --squash 'Jesper-A-up-preload-skip'
git switch 'main'
git merge --ff-only 'Jesper-A-up-preload-skip'
git switch 'main'
git merge 'Jesper-A-up-preload-skip'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 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!142
No description provided.