[pr-feature][startup][shaders] Preload: save the pipeline library every N seconds so a stopped preload keeps its work (DARNER_PRELOAD_SAVE_EVERY, off by default) #147

Manually merged
TrustNo1 merged 1 commit from Jesper-A/Darner:up-preload-library-chunks into main 2026-12-04 02:41:08 +00:00
Contributor

Refs #128

Contributor role (optional)

  • Fluxer ID:

What it changes

Step 3 of the plan in #128 ("Save into_library progress as it goes, so 'Play now' keeps what was made"). Steps 1 and 2 are the draft PRs #140 (DARNER_PRELOAD_RESUME) and #142 (DARNER_PRECOMPILE_SKIP_DONE). This one does not depend on them.

Before: the last step of a preload, warm::into_library (apps/darner/src/warm.rs), builds every early and slow pipeline and saves the host pipeline library once, at the end. A preload stopped by Play now, Quit or a crash before that save keeps none of them, and the next start builds them again.

Now: DARNER_PRELOAD_SAVE_EVERY=<seconds> (off by default; 30 or more, a smaller number is raised to 30; 0 or anything that is not a whole number is off). With it set, a thread named darner-pipelines-save calls known::keep_library (the save a normal run makes) every that many seconds while at least one library worker is alive. The final save at the end is unchanged. A pipeline that is in the library is loaded in milliseconds by the next pass, so the library itself is the mark; no done marks are written.

It is a time and not a pipeline count because a save writes the whole file however few pipelines were added.

Files: apps/darner/src/warm.rs (the switch, a worker counter, the saver thread, two unit tests), README.md (one switch row), docs/findings.md (a short section). No new unsafe.

Risks to review (why this is WIP)

  • Each save rewrites the whole pipeline library file (about 2 GB on a warmed install). The cost of a save is not measured, so 30 s may be too often.
  • Safety while the workers are inside known::make rests on the saver taking the library's saving write lock (crates/darner-gpu/src/pipeline/library.rs, save_library) while stores read it. Nothing exercises this under load; the unit tests use a counter, not the real library.
  • A stopped preload (Play now, Quit, crash) with this switch on has not been run in game, so "keeps what it built" is not shown yet.

How it was tested

  • Tested revision: branch up-preload-library-chunks @ 144038871 on top of main 57dea7f23.
  • Commands and results (all on 144038871):
    • cargo test --locked -j 4 -p darner --bin darner save_every: 1 passed.
    • cargo test --locked -j 4 -p darner --bin darner chunk_saver: 1 passed.
    • cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings: clean.
    • cargo xtask policy: 553 files ok.
  • Gameplay, when relevant: not run in game. No preload was stopped with the switch set. The GPU and profile of our PC are RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, Series S, DLSS Performance, but none of it was used for this change.
  • Before and after, when relevant: no measurement. The time a save takes at 2 GB, and what it does to the preload's total time, are not known.
  • Shader wave sizes tested, when relevant: not applicable (no shader change).
  • Coverage gaps:
    • Not run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo test --workspace --locked. Upstream has no CI, so nothing else has run this. No gate was run on any other commit.
    • The three risks above.
    • A crash during a save (a half-written library file) was not tried; the saver uses the same save a normal run uses, but this was not checked here.
    • Other GPUs, other disks (a slow disk makes each save longer), Series X.

Spec dependence

  • Likely general (helps any card): the saver and the switch are launcher and file code and do not touch the GPU path.
  • May depend on our specs: how long a save takes and how often 30 s is too often depend on the disk and on the size of the library (about 2 GB on a warmed install here). Nothing was timed.
  • Untested elsewhere: all other PCs and disks, Series X, frame generation, ray tracing, Linux/Proton.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: 553 files ok).
  • I recorded this PR's dependencies below.
    • Depends on: none (it only shares the end of docs/findings.md and the README.md switch table with #140 and #142; see below)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #140 and #142 (same issue, steps 1 and 2; both also append a section at the end of docs/findings.md). A trial merge of this branch with each (git merge-tree --write-tree) conflicts only in docs/findings.md; README.md and warm.rs merge cleanly. Whichever lands second needs the two findings sections kept. #130 merges cleanly; #132 touches neither warm.rs nor README.md. #125 (captures stderr of failed warm workers) also edits warm.rs; a trial merge with #125's head (git merge-tree --write-tree) is clean. #145, #118, #110, #75, #59, #37, #36 and #34 touch README.md or docs/findings.md and merge cleanly with this branch. #9, #10, #12, #14, #15, #16, #17 and #18 conflict with it in README.md or docs/findings.md or elsewhere, but those also conflict with main as it is now.

Drafted with AI assistance (Claude Code).

Refs #128 ## Contributor role (optional) - Fluxer ID: ## What it changes Step 3 of the plan in #128 ("Save `into_library` progress as it goes, so 'Play now' keeps what was made"). Steps 1 and 2 are the draft PRs #140 (`DARNER_PRELOAD_RESUME`) and #142 (`DARNER_PRECOMPILE_SKIP_DONE`). This one does not depend on them. Before: the last step of a preload, `warm::into_library` (`apps/darner/src/warm.rs`), builds every early and slow pipeline and saves the host pipeline library once, at the end. A preload stopped by Play now, Quit or a crash before that save keeps none of them, and the next start builds them again. Now: `DARNER_PRELOAD_SAVE_EVERY=<seconds>` (off by default; 30 or more, a smaller number is raised to 30; 0 or anything that is not a whole number is off). With it set, a thread named `darner-pipelines-save` calls `known::keep_library` (the save a normal run makes) every that many seconds while at least one library worker is alive. The final save at the end is unchanged. A pipeline that is in the library is loaded in milliseconds by the next pass, so the library itself is the mark; no done marks are written. It is a time and not a pipeline count because a save writes the whole file however few pipelines were added. Files: `apps/darner/src/warm.rs` (the switch, a worker counter, the saver thread, two unit tests), `README.md` (one switch row), `docs/findings.md` (a short section). No new `unsafe`. ### Risks to review (why this is WIP) - [ ] Each save rewrites the whole pipeline library file (about 2 GB on a warmed install). The cost of a save is not measured, so 30 s may be too often. - [ ] Safety while the workers are inside `known::make` rests on the saver taking the library's `saving` write lock (`crates/darner-gpu/src/pipeline/library.rs`, `save_library`) while stores read it. Nothing exercises this under load; the unit tests use a counter, not the real library. - [ ] A stopped preload (Play now, Quit, crash) with this switch on has not been run in game, so "keeps what it built" is not shown yet. ## How it was tested - Tested revision: branch `up-preload-library-chunks` @ 144038871 on top of `main` 57dea7f23. - Commands and results (all on 144038871): - `cargo test --locked -j 4 -p darner --bin darner save_every`: 1 passed. - `cargo test --locked -j 4 -p darner --bin darner chunk_saver`: 1 passed. - `cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings`: clean. - `cargo xtask policy`: 553 files ok. - Gameplay, when relevant: not run in game. No preload was stopped with the switch set. The GPU and profile of our PC are RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, Series S, DLSS Performance, but none of it was used for this change. - Before and after, when relevant: no measurement. The time a save takes at 2 GB, and what it does to the preload's total time, are not known. - Shader wave sizes tested, when relevant: not applicable (no shader change). - Coverage gaps: - Not run: `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` and `cargo test --workspace --locked`. Upstream has no CI, so nothing else has run this. No gate was run on any other commit. - The three risks above. - A crash during a save (a half-written library file) was not tried; the saver uses the same save a normal run uses, but this was not checked here. - Other GPUs, other disks (a slow disk makes each save longer), Series X. ## Spec dependence - Likely general (helps any card): the saver and the switch are launcher and file code and do not touch the GPU path. - May depend on our specs: how long a save takes and how often 30 s is too often depend on the disk and on the size of the library (about 2 GB on a warmed install here). Nothing was timed. - Untested elsewhere: all other PCs and disks, Series X, frame generation, ray tracing, Linux/Proton. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: 553 files ok). - [x] I recorded this PR's dependencies below. - Depends on: none (it only shares the end of `docs/findings.md` and the `README.md` switch table with #140 and #142; see below) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #140 and #142 (same issue, steps 1 and 2; both also append a section at the end of `docs/findings.md`). A trial merge of this branch with each (`git merge-tree --write-tree`) conflicts only in `docs/findings.md`; `README.md` and `warm.rs` merge cleanly. Whichever lands second needs the two findings sections kept. #130 merges cleanly; #132 touches neither `warm.rs` nor `README.md`. #125 (captures stderr of failed warm workers) also edits `warm.rs`; a trial merge with #125's head (`git merge-tree --write-tree`) is clean. #145, #118, #110, #75, #59, #37, #36 and #34 touch `README.md` or `docs/findings.md` and merge cleanly with this branch. #9, #10, #12, #14, #15, #16, #17 and #18 conflict with it in `README.md` or `docs/findings.md` or elsewhere, but those also conflict with `main` as it is now. Drafted with AI assistance (Claude Code).
DARNER_PRELOAD_SAVE_EVERY=<seconds, at least 30>, off by default, makes
into_library save the host pipeline library every that many seconds via
known::keep_library, so a stopped preload keeps what it built.

This change was made with AI assistance (Claude Code).
Jesper-A changed title from WIP: [pr-feature][startup][shaders] Preload: save the pipeline library every N seconds so a stopped preload keeps its work (DARNER_PRELOAD_SAVE_EVERY, off by default) to [pr-feature][startup][shaders] Preload: save the pipeline library every N seconds so a stopped preload keeps its work (DARNER_PRELOAD_SAVE_EVERY, off by default) 2026-12-04 01:38:55 +00:00
Owner

Second-opinion review: merge as is (opt-in). Saves go through temp file + rename, so stopping during a save can't corrupt the library. Stores made during a save are queued, a save with nothing added is skipped, and the worker count drops even if a worker panics, so the saver can't run forever. One unmeasured cost: each save serialises the whole library (about 2 GB) through RAM and holds worker stores while it writes, which matters on 16 GB PCs. Before anyone recommends it to players, one measured stopped preload (time and peak memory) would help.

Second-opinion review: merge as is (opt-in). Saves go through temp file + rename, so stopping during a save can't corrupt the library. Stores made during a save are queued, a save with nothing added is skipped, and the worker count drops even if a worker panics, so the saver can't run forever. One unmeasured cost: each save serialises the whole library (about 2 GB) through RAM and holds worker stores while it writes, which matters on 16 GB PCs. Before anyone recommends it to players, one measured stopped preload (time and peak memory) would help.
TrustNo1 manually merged commit 140980dd65 into main 2026-12-04 02:41:06 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 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!147
No description provided.