Skip to content

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

Open
Lyrnc wants to merge 2 commits into
trustno1-coder:mainfrom
Lyrnc:perf/early-library-save
Open

Lyrnc wants to merge 2 commits into
trustno1-coder:mainfrom
Lyrnc:perf/early-library-save

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

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

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 2a33b73 (rebased onto 41adb55), 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

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 and others added 2 commits November 30, 2026 06:53
…in the world), not first after 180 s

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 <noreply@anthropic.com>
…w, not as a load that failed

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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant