Pipeline library: a cold run saves it early (200 new pipelines, or 30 s in the world), not first after 180 s #3702

Closed
github-bot wants to merge 2 commits from github-bot/gh-3702 into main AGit
Owner

@⁠Lyrnc on GitHub · 2026-11-30 04:21 UTC · original
Lyrnc:perf/early-library-save → main · +189 −6 · 1 files · 2 commits · closed without merging

Problem

A run that dies in its first minutes keeps none of the pipelines it made, and the next start is cold again.

  • A cold run is one burst of new pipelines from start to end. While the workers are busy, save_while_busy() saves at most every VICTORY_LIBRARY_SAVE_BUSY_S (180 s), and the first busy save of a run waits a full interval. The save when the queue runs dry never comes in such a run.
  • VICTORY_LIBRARY_SAVE_MADE=N (#1679) is off by default, and only covers libraries under 64 MB at launch.
  • So a run that dies before 180 s, as the device losses of #3050 and the others in T06 do (40-190 s into the world), leaves the library as it was at launch. The code's own comment tells of one: 708 pipelines made, dead 43 s into the game, library left at 8,262 bytes.
  • The trail of every new pipeline said the library did not load it: ... (0x80070057). A load answers E_INVALIDARG for a name the library does not hold, which is the normal first time of a pipeline. #3050 read that line as "the pipeline library fails to load 72/72 entries".

Fix

  1. Early saves (library.rs, save_while_busy). Two saves, each once a run, from the pipeline workers (the only callers of save_while_busy, threads victory-pipelines-N), never from the submitting thread:

    • once 200 pipelines were added since the last save;
    • once the title has been 30 s in the world (crate::world_since, the first frame of 500 draws), with at least one pipeline added.

    Gates, in Early::due (a pure function, unit-tested):

    • Neither runs while a library load is in the driver (loads_running(), whatever VICTORY_LIBRARY_SAVE_AFTER_LOADS says). The serialise waits for the load and every later load waits behind the serialise (the comment's 20.8 s save and 15 s freeze). The save stays due, and a later pipeline makes it. Loads are asked only of a save that is due, so the steady state takes no extra lock.
    • Neither runs once the library is 256 MB or more (its last save's size, else its file's at launch). A warm library saves as before.
    • save()'s own rules still apply: its interval (save_every, at least 20 s), the longer interval under memory pressure, VICTORY_LIBRARY_SAVE_QUIET, and another run's writer lock. An early save counts as made only once a save wrote the library (a new SAVES counter). One that was refused stays due.

    After an early save, the busy saves come every VICTORY_LIBRARY_SAVE_BUSY_S from it, as before. The save when the queue runs dry and the one at exit are unchanged.

    VICTORY_LIBRARY_SAVE_EARLY=<pipelines>,<seconds>: default 200,30. Either part 0 turns that save off; 0 alone turns both off, as before.

    Log: host pipeline library saved early (VICTORY_LIBRARY_SAVE_EARLY=0: not) added=N by="pipelines added"|"time in the world".

  2. The trail (not_loaded): a pipeline the library does not hold is new: not in the library yet. Other refusals, and every one with VICTORY_LIBRARY_LOADS=never, read as before (the library did not load it: <error>). This is a separate commit; drop it if you want one change per PR.

Verification

Windows 11, rustc 1.98.1 (the pinned toolchain), Ryzen 7 9800X3D. On 2a33b73a (rebased onto 41adb551), with its own target directory (C:\gt-lib):

  • cargo check -p victory-gpu --locked -j 6: passes (the log shows victory-gpu built from C:\g-libsave\crates\victory-gpu). None of the crate's 18 warnings is in library.rs; they are existing dead code and unused names elsewhere (shader_cache.rs:14, host/font.rs:55, host.rs, resource.rs:3573, streamline.rs:1004 and others).
  • cargo test -p victory-gpu --lib --locked -j 6 -- library: 20 passed, 0 failed, 0 ignored. The new ones:
    • the_early_saves_by_the_switch: unset or unreadable gives 200,30; 0 (and 0,0) none; 50, 50,10, 0,10, 50,0.
    • each_early_save_comes_once: 199 pipelines none, 200 the first; made once; 30 s in the world the second, whether or not the first was made; the pipelines' first when both are due, then the world's; nothing added, none; either part 0.
    • no_early_save_of_a_large_library_or_beside_a_load: none at 256 MB or for a warm 1.3 GB library; none while a load runs, and still due after it; loads asked only of a save that is due.
    • a_pipeline_not_in_the_library_is_new: E_INVALIDARG is "new", E_OUTOFMEMORY is told as it came.
    • The library's other 16 tests (mapping, replace, rebuild, shards, the save interval by size, WARP pipelines loaded from the library) pass as before.
  • cargo clippy -p victory-gpu --all-targets --locked -j 6 and the same with --all-features: no warning on a touched line. The two in library.rs are on main's lines: incompatible_msrv at 90 (try_lock) and manual_is_multiple_of at 776. Both runs finish with warnings only (victory-gpu lib 27 / 25, lib test 30 / 24, victory-shader 3), all outside the diff.

NOT tested

  • No game run. Nobody has seen an early save in a real log. Not checked:
    • a cold library, 60-90 s in the world, the process ended, then a restart: loaded against made (the T06 check, under 5 min of game);
    • how long the first early save takes on an RTX card (a library of 200 pipelines; the comment's 35 ms for 26 MB is the only figure), and whether it shows as a long frame. The save is on a worker, but stores wait for it (library.saving) unless VICTORY_LIBRARY_STORE_LATER hands the pipelines out first (on by default).
  • The 200 and 30 s are picked, not measured.
  • No save on the way out of a device loss (T06's other idea). Not done here: Serialize after a removal is not known to work.
  • The concurrency (two workers asking at once) is read from the code, not tested: save()'s own interval lets one through, and EARLY_DONE's fetch_or logs once.

Overlap

  • gh pr list --state open --search: "library save", "pipeline library", "LIBRARY_SAVE", "save early", "cold library", "save_while_busy".
  • #1679 (101Leafy, open): VICTORY_LIBRARY_SAVE_MADE=N (off by default; the code is already on main). This branch keeps it as it is. The early saves come first in save_while_busy, so with both, the first early save is this one, then SAVE_MADE's every N.
  • #1746 (101Leafy, open; also on main): VICTORY_LIBRARY_SAVE_AFTER_LOADS=1. The early saves never run beside a load, with or without it.
  • #1989 (NotADonky43, open): persists the early list (first-use pipeline history) without serialising the driver library. Different file, same reason (an early end loses the run's work). Merges cleanly with this.
  • #3459 (OGShotz, open): no rebuild at the end of a short run (compact). Same file, merges cleanly.
  • #2577 (steven-seagull27, open): compact() and the writer lock. Merges cleanly.

AI use

Claude Code (Claude Opus 5.5) wrote the change and its unit tests, ran the checks listed above, and wrote this note. Nothing was run in game.

🤖 Generated with Claude Code

**@⁠Lyrnc** on GitHub · 2026-11-30 04:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3702) `Lyrnc:perf/early-library-save` → `main` · +189 −6 · 1 files · 2 commits · closed without merging ## Problem A run that dies in its first minutes keeps none of the pipelines it made, and the next start is cold again. - A cold run is one burst of new pipelines from start to end. While the workers are busy, `save_while_busy()` saves at most every `VICTORY_LIBRARY_SAVE_BUSY_S` (180 s), and the first busy save of a run waits a full interval. The save when the queue runs dry never comes in such a run. - `VICTORY_LIBRARY_SAVE_MADE=N` (#1679) is off by default, and only covers libraries under 64 MB at launch. - So a run that dies before 180 s, as the device losses of #3050 and the others in T06 do (40-190 s into the world), leaves the library as it was at launch. The code's own comment tells of one: 708 pipelines made, dead 43 s into the game, library left at 8,262 bytes. - The trail of every new pipeline said `the library did not load it: ... (0x80070057)`. A load answers `E_INVALIDARG` for a name the library does not hold, which is the normal first time of a pipeline. #3050 read that line as "the pipeline library fails to load 72/72 entries". ## Fix 1. **Early saves** (`library.rs`, `save_while_busy`). Two saves, each once a run, from the pipeline workers (the only callers of `save_while_busy`, threads `victory-pipelines-N`), never from the submitting thread: - once 200 pipelines were added since the last save; - once the title has been 30 s in the world (`crate::world_since`, the first frame of 500 draws), with at least one pipeline added. Gates, in `Early::due` (a pure function, unit-tested): - Neither runs while a library load is in the driver (`loads_running()`, whatever `VICTORY_LIBRARY_SAVE_AFTER_LOADS` says). The serialise waits for the load and every later load waits behind the serialise (the comment's 20.8 s save and 15 s freeze). The save stays due, and a later pipeline makes it. Loads are asked only of a save that is due, so the steady state takes no extra lock. - Neither runs once the library is 256 MB or more (its last save's size, else its file's at launch). A warm library saves as before. - `save()`'s own rules still apply: its interval (`save_every`, at least 20 s), the longer interval under memory pressure, `VICTORY_LIBRARY_SAVE_QUIET`, and another run's writer lock. An early save counts as made only once a save wrote the library (a new `SAVES` counter). One that was refused stays due. After an early save, the busy saves come every `VICTORY_LIBRARY_SAVE_BUSY_S` from it, as before. The save when the queue runs dry and the one at exit are unchanged. `VICTORY_LIBRARY_SAVE_EARLY=<pipelines>,<seconds>`: default `200,30`. Either part `0` turns that save off; `0` alone turns both off, as before. Log: `host pipeline library saved early (VICTORY_LIBRARY_SAVE_EARLY=0: not) added=N by="pipelines added"|"time in the world"`. 2. **The trail** (`not_loaded`): a pipeline the library does not hold is `new: not in the library yet`. Other refusals, and every one with `VICTORY_LIBRARY_LOADS=never`, read as before (`the library did not load it: <error>`). This is a separate commit; drop it if you want one change per PR. ## Verification Windows 11, rustc 1.98.1 (the pinned toolchain), Ryzen 7 9800X3D. On 2a33b73a (rebased onto 41adb551), with its own target directory (`C:\gt-lib`): - `cargo check -p victory-gpu --locked -j 6`: passes (the log shows `victory-gpu` built from `C:\g-libsave\crates\victory-gpu`). None of the crate's 18 warnings is in `library.rs`; they are existing dead code and unused names elsewhere (`shader_cache.rs:14`, `host/font.rs:55`, `host.rs`, `resource.rs:3573`, `streamline.rs:1004` and others). - `cargo test -p victory-gpu --lib --locked -j 6 -- library`: **20 passed, 0 failed**, 0 ignored. The new ones: - `the_early_saves_by_the_switch`: unset or unreadable gives `200,30`; `0` (and `0,0`) none; `50`, `50,10`, `0,10`, `50,0`. - `each_early_save_comes_once`: 199 pipelines none, 200 the first; made once; 30 s in the world the second, whether or not the first was made; the pipelines' first when both are due, then the world's; nothing added, none; either part 0. - `no_early_save_of_a_large_library_or_beside_a_load`: none at 256 MB or for a warm 1.3 GB library; none while a load runs, and still due after it; loads asked only of a save that is due. - `a_pipeline_not_in_the_library_is_new`: `E_INVALIDARG` is "new", `E_OUTOFMEMORY` is told as it came. - The library's other 16 tests (mapping, replace, rebuild, shards, the save interval by size, WARP pipelines loaded from the library) pass as before. - `cargo clippy -p victory-gpu --all-targets --locked -j 6` and the same with `--all-features`: no warning on a touched line. The two in `library.rs` are on main's lines: `incompatible_msrv` at 90 (`try_lock`) and `manual_is_multiple_of` at 776. Both runs finish with warnings only (victory-gpu lib 27 / 25, lib test 30 / 24, victory-shader 3), all outside the diff. ## NOT tested - **No game run.** Nobody has seen an early save in a real log. Not checked: - a cold library, 60-90 s in the world, the process ended, then a restart: `loaded` against `made` (the T06 check, under 5 min of game); - how long the first early save takes on an RTX card (a library of 200 pipelines; the comment's 35 ms for 26 MB is the only figure), and whether it shows as a long frame. The save is on a worker, but stores wait for it (`library.saving`) unless `VICTORY_LIBRARY_STORE_LATER` hands the pipelines out first (on by default). - The 200 and 30 s are picked, not measured. - No save on the way out of a device loss (T06's other idea). Not done here: `Serialize` after a removal is not known to work. - The concurrency (two workers asking at once) is read from the code, not tested: `save()`'s own interval lets one through, and `EARLY_DONE`'s `fetch_or` logs once. ## Overlap - `gh pr list --state open --search`: "library save", "pipeline library", "LIBRARY_SAVE", "save early", "cold library", "save_while_busy". - **#1679** (101Leafy, open): `VICTORY_LIBRARY_SAVE_MADE=N` (off by default; the code is already on main). This branch keeps it as it is. The early saves come first in `save_while_busy`, so with both, the first early save is this one, then `SAVE_MADE`'s every N. - **#1746** (101Leafy, open; also on main): `VICTORY_LIBRARY_SAVE_AFTER_LOADS=1`. The early saves never run beside a load, with or without it. - **#1989** (NotADonky43, open): persists the early list (first-use pipeline history) without serialising the driver library. Different file, same reason (an early end loses the run's work). Merges cleanly with this. - **#3459** (OGShotz, open): no rebuild at the end of a short run (`compact`). Same file, merges cleanly. - #2577 (steven-seagull27, open): `compact()` and the writer lock. Merges cleanly. ## AI use Claude Code (Claude Opus 5.5) wrote the change and its unit tests, ran the checks listed above, and wrote this note. Nothing was run in game. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A cold run is one burst of new pipelines from start to end, so the busy
save (one every VICTORY_LIBRARY_SAVE_BUSY_S, 180 s by default) saved
nothing until its first 180 s. A run that died before that (a device lost
40 s into the world) left the library as it was at launch, and the next
start was cold again. VICTORY_LIBRARY_SAVE_MADE (off by default) only
covers libraries under 64 MB at launch and saves every 20 s.

Two early saves, each once a run, from the pipeline workers' busy save
(never the submitting thread):
- once 200 pipelines were added since the last save;
- once the title has been 30 s in the world, with something added.
Neither while a library load is in the driver (whatever
VICTORY_LIBRARY_SAVE_AFTER_LOADS says): the save stays due for a later
pipeline. Neither once the library is 256 MB or more (its last save, else
its file at launch): a warm library is as before. save()'s own interval,
its memory-pressure interval and the other run's writer lock still apply;
an early save is marked done only once one wrote the library. The busy
saves then come every VICTORY_LIBRARY_SAVE_BUSY_S from the last early one.

VICTORY_LIBRARY_SAVE_EARLY=<pipelines>,<seconds> (default 200,30; either 0:
not that one; 0: none, as before).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A load answers E_INVALIDARG for a name the library does not hold: the
first time of every pipeline. The trail said "the library did not load it
(... 0x80070057)", and device-loss reports quoted that as a failure. It now
says "new: not in the library yet"; other refusals, and every one with
VICTORY_LIBRARY_LOADS=never, are told as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 04:22:29 +00:00
github-bot force-pushed github-bot/gh-3702 from 2a33b73a55 to e51d57a29a 2026-11-30 18:28:40 +00:00 Compare
Author
Owner

@⁠icdmkg2 on GitHub · 2026-11-30 21:57 UTC · original

Tested on an RTX 5060 Laptop (8 GB), Ryzen 7 260, 31 GB RAM, Windows 11. Series S, DLSS Performance, release build. Each run was closed by force about 3 minutes after the first frame of 1,000 draws, which is the case this PR is about: no exit save, and well before the 180 s busy save.

Without the PR (main at e1251c3), 5 runs on one cache directory. The library was saved once, about 30 s in, with ~30 pipelines, and never again. It stayed at about 0.7 MB, so every start was cold:

Run Loaded Made
1 to 5 0 to 173 1,519 to 1,706

With the PR merged onto the same main, 3 runs from a fresh cache directory:

Run Saves Loaded Made Library at end
1 6 (early: added=375 by="pipelines added", then by="time in the world") 130 1,557 16.6 MB
2 2 (early: added=812) 671 888 112.7 MB
3 1 1,605 128 112.8 MB

cargo test -p victory-gpu --lib -- pipeline::library: 24 passed.

Frame rates from these runs aren't comparable. Run 3 still had frames of 1 to 13 s, and the memory lines put that on the PC's memory, not on the library: the process held 24.8 GB private and the PC had 1.2 to 2 GB free, so compiles went one at a time under the soft floor. That seems to be a separate problem from the one this PR fixes.

**@⁠icdmkg2** on GitHub · 2026-11-30 21:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3702#issuecomment-7293148731) Tested on an RTX 5060 Laptop (8 GB), Ryzen 7 260, 31 GB RAM, Windows 11. Series S, DLSS Performance, release build. Each run was closed by force about 3 minutes after the first frame of 1,000 draws, which is the case this PR is about: no exit save, and well before the 180 s busy save. **Without the PR** (`main` at e1251c3), 5 runs on one cache directory. The library was saved once, about 30 s in, with ~30 pipelines, and never again. It stayed at about 0.7 MB, so every start was cold: | Run | Loaded | Made | |---|---|---| | 1 to 5 | 0 to 173 | 1,519 to 1,706 | **With the PR** merged onto the same `main`, 3 runs from a fresh cache directory: | Run | Saves | Loaded | Made | Library at end | |---|---|---|---|---| | 1 | 6 (early: `added=375 by="pipelines added"`, then `by="time in the world"`) | 130 | 1,557 | 16.6 MB | | 2 | 2 (early: `added=812`) | 671 | 888 | 112.7 MB | | 3 | 1 | 1,605 | 128 | 112.8 MB | `cargo test -p victory-gpu --lib -- pipeline::library`: 24 passed. Frame rates from these runs aren't comparable. Run 3 still had frames of 1 to 13 s, and the memory lines put that on the PC's memory, not on the library: the process held 24.8 GB private and the PC had 1.2 to 2 GB free, so compiles went one at a time under the soft floor. That seems to be a separate problem from the one this PR fixes.
Author
Owner

@⁠Lyrnc on GitHub · 2026-12-01 03:56 UTC · original

Thanks @⁠icdmkg2. That's the case this PR is for, on an 8 GB laptop:

  • Without it, all five force-closed runs started cold. The library stayed at ~0.7 MB (about 30 pipelines, saved once early on), and every start made 1,519-1,706 pipelines.
  • With it, the first run saved early (added=375) and then on time, the second start loaded 671 and made 888, and the third loaded 1,605 and made only 128, from a ~113 MB library.

So a run that never reaches the exit save or the 180 s busy save keeps its pipelines.

Agreed on run 3's frames of 1-13 s. With 1.2-2 GB of the PC's memory free, compiles were held to one at a time under the soft floor. That's the memory side, not the library.

AI use: Claude Code (Claude Opus 5.5) read your results and wrote this.

**@⁠Lyrnc** on GitHub · 2026-12-01 03:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3702#issuecomment-7300213753) Thanks @⁠icdmkg2. That's the case this PR is for, on an 8 GB laptop: - Without it, all five force-closed runs started cold. The library stayed at ~0.7 MB (about 30 pipelines, saved once early on), and every start made 1,519-1,706 pipelines. - With it, the first run saved early (`added=375`) and then on time, the second start loaded 671 and made 888, and the third loaded 1,605 and made only 128, from a ~113 MB library. So a run that never reaches the exit save or the 180 s busy save keeps its pipelines. Agreed on run 3's frames of 1-13 s. With 1.2-2 GB of the PC's memory free, compiles were held to one at a time under the soft floor. That's the memory side, not the library. AI use: Claude Code (Claude Opus 5.5) read your results and wrote this.
github-bot force-pushed github-bot/gh-3702 from e51d57a29a to c3675fd593 2026-12-01 04:59:41 +00:00 Compare
github-bot closed this pull request 2026-12-01 18:51:31 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:49 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3702#issuecomment-7321624678) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/trustno1-coder--VIctory-NVIDIA!3702
No description provided.