Pipeline library: VICTORY_LIBRARY_TRIM=once lets the file's pages go once, not after every burst of loads (off by default) #4921

Open
github-bot wants to merge 3 commits from github-bot/gh-4920 into main AGit
Owner

@⁠xteral67 on GitHub · 2026-12-01 14:07 UTC · original
xteral67:library-trim-once → main · +133 −12 · 1 files · 3 commits · open

What it changes

trim() lets go of the whole mapped library file (VirtualUnlock) after every burst of pipeline loads. On a PC with little free memory, the next pipeline new to a street then reads its pages back from disk one fault at a time, and the frame waits: "pipeline library: slow load" lines of 2–13 s, with the driver's own call taking all of it.

  • VICTORY_LIBRARY_TRIM=once: the pages go after the first burst only (the world's load). After that, Windows ages pages out by use and keeps what is read. Unset or always: as before. 0: never, as before.
  • The "slow load" line also says page_faults during the load, trims (how many times the whole file was let go), since_trim_s and free_mb. This tells a wait on paged-out library pages from other waits.

How it was tested

  • RTX 3080 Ti 12 GB, i5-14600KF, 32 GB RAM (often under 1 GB free), driver 621.40. Series X profile, 1440p, DLSS quality, FSR frame generation 2x, no ray tracing. Played by hand in town and by the water, diagnostics build.
  • Before (default, trim after each burst): 8 rides, about 66 minutes in all: 46 slow loads, longest 2.7–12.9 s per ride.
  • After (once): 6 rides, about 28 minutes in all: 6 slow loads, longest 4.0 s. Four of them were at the world's load (43 s after the one trim). The other two (2.1 and 3.0 s) came with 451 MB of RAM free.
  • Other changes ran in the same builds (window placement, render-target memory), so the frame times of these rides are not given here as this change's effect.
  • Not tested: cargo test, other cards, the Series S profile, Linux.
  • Commit tested: the same library.rs change in a tree based on v2026.11.30.03, where once was the default. This branch makes it opt-in; that line is the only difference.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #3747, #3702, #1746, #1750 (closed) change when the library saves or loads, not when its pages are let go.

🤖 Generated with Claude Code

**@⁠xteral67** on GitHub · 2026-12-01 14:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920) `xteral67:library-trim-once` → `main` · +133 −12 · 1 files · 3 commits · open ## What it changes `trim()` lets go of the whole mapped library file (VirtualUnlock) after every burst of pipeline loads. On a PC with little free memory, the next pipeline new to a street then reads its pages back from disk one fault at a time, and the frame waits: "pipeline library: slow load" lines of 2–13 s, with the driver's own call taking all of it. - `VICTORY_LIBRARY_TRIM=once`: the pages go after the first burst only (the world's load). After that, Windows ages pages out by use and keeps what is read. Unset or `always`: as before. `0`: never, as before. - The "slow load" line also says `page_faults` during the load, `trims` (how many times the whole file was let go), `since_trim_s` and `free_mb`. This tells a wait on paged-out library pages from other waits. ## How it was tested - RTX 3080 Ti 12 GB, i5-14600KF, 32 GB RAM (often under 1 GB free), driver 621.40. Series X profile, 1440p, DLSS quality, FSR frame generation 2x, no ray tracing. Played by hand in town and by the water, diagnostics build. - Before (default, trim after each burst): 8 rides, about 66 minutes in all: 46 slow loads, longest 2.7–12.9 s per ride. - After (`once`): 6 rides, about 28 minutes in all: 6 slow loads, longest 4.0 s. Four of them were at the world's load (43 s after the one trim). The other two (2.1 and 3.0 s) came with 451 MB of RAM free. - Other changes ran in the same builds (window placement, render-target memory), so the frame times of these rides are not given here as this change's effect. - Not tested: `cargo test`, other cards, the Series S profile, Linux. - Commit tested: the same `library.rs` change in a tree based on v2026.11.30.03, where `once` was the default. This branch makes it opt-in; that line is the only difference. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #3747, #3702, #1746, #1750 (closed) change when the library saves or loads, not when its pages are let go. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:11:43 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 14:13 UTC · original

On c8cbc922, a pipeline load clears TRIMMED while the background trim can still be in flight. In once mode the byte counter stays at zero until that worker finishes, so the next idle period can queue a second trim.

1e1c7fee gives once mode its own reservation, claimed before the worker starts. If the worker fails to spawn, the reservation is released for the next attempt. The always mode continues to use the per-burst gate.

I ran the exact Windows trim scheduler with a stubbed worker queue and file-page operation. With the first job held pending across another load and idle period, the author head queued two jobs and the patch queued one. In the same fixture, a failed spawn retried, always queued twice across two load bursts, and 0 queued nothing. The staged asset policy passed.

Please keep the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change in.

AI-assisted with OpenAI Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 14:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#issuecomment-7313899490) On `c8cbc922`, a pipeline load clears `TRIMMED` while the background trim can still be in flight. In `once` mode the byte counter stays at zero until that worker finishes, so the next idle period can queue a second trim. [1e1c7fee](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/1e1c7fee559377772c4e21734ae9d7b757cace4d) gives `once` mode its own reservation, claimed before the worker starts. If the worker fails to spawn, the reservation is released for the next attempt. The `always` mode continues to use the per-burst gate. I ran the exact Windows trim scheduler with a stubbed worker queue and file-page operation. With the first job held pending across another load and idle period, the author head queued two jobs and the patch queued one. In the same fixture, a failed spawn retried, `always` queued twice across two load bursts, and `0` queued nothing. The staged asset policy passed. Please keep the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change in. AI-assisted with OpenAI Codex.
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 14:35 UTC · original · reviewed

AI-assisted review; I used an AI assistant to inspect this diff.

**@⁠gut0to** on GitHub · 2026-12-01 14:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#pullrequestreview-6133429468) · **reviewed** AI-assisted review; I used an AI assistant to inspect this diff.
@ -480,0 +493,4 @@
}
static MODE: OnceLock<Mode> = OnceLock::new();
static TRIM_QUEUED_ONCE: AtomicBool = AtomicBool::new(false);
let mode = MODE.get_or_init(|| match std::env::var("VICTORY_LIBRARY_TRIM").as_deref().map(str::trim) {
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 14:35 UTC · original

Could the Never/Once/Always policy be extracted into a pure helper and covered with tests for the first trim and the post-load transition? This adds a new environment-controlled mode, but no regression test pins that once trims after the intended burst only while always preserves the existing re-arm behavior. A CPU-only policy test would make the state transition explicit without mutating process environment or spawning the trim worker. AI-assisted review; I traced the mode selection through the load timestamp and trim gate.

**@⁠gut0to** on GitHub · 2026-12-01 14:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#discussion_r4755745976) Could the `Never`/`Once`/`Always` policy be extracted into a pure helper and covered with tests for the first trim and the post-load transition? This adds a new environment-controlled mode, but no regression test pins that `once` trims after the intended burst only while `always` preserves the existing re-arm behavior. A CPU-only policy test would make the state transition explicit without mutating process environment or spawning the trim worker. AI-assisted review; I traced the mode selection through the load timestamp and trim gate.
Author
Owner

@⁠xteral67 on GitHub · 2026-12-01 17:00 UTC · original

Done in d1b74a65: the mode, the gate choice and the claim are now pure helpers (TrimMode::parse, trim_gate, claim_trim), with five CPU-only tests: parsing, never, always (one trim per burst, re-armed by a load), once (first burst only, also with a load while the worker still runs), and a failed worker start freeing the gate. Not run yet: I have no Windows test run for this branch at hand; I will report the result here.

**@⁠xteral67** on GitHub · 2026-12-01 17:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#issuecomment-7318586676) Done in d1b74a65: the mode, the gate choice and the claim are now pure helpers (`TrimMode::parse`, `trim_gate`, `claim_trim`), with five CPU-only tests: parsing, never, always (one trim per burst, re-armed by a load), once (first burst only, also with a load while the worker still runs), and a failed worker start freeing the gate. Not run yet: I have no Windows test run for this branch at hand; I will report the result here.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 17:02 UTC · original

I ran the five library_trim_* tests from d1b74a65 on Windows. I compiled the exact test bodies, load fixture, and the three pure helpers with rustc --test. All five passed.

The once test confirms that a load during the worker's run only re-arms the burst gate. The failed-spawn case confirms a new claim can succeed. This was the CPU-only check of the gate and retry; the actual mapped file and worker weren't used.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 17:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#issuecomment-7318647521) I ran the five `library_trim_*` tests from `d1b74a65` on Windows. I compiled the exact test bodies, `load` fixture, and the three pure helpers with `rustc --test`. All five passed. The `once` test confirms that a load during the worker's run only re-arms the burst gate. The failed-spawn case confirms a new claim can succeed. This was the CPU-only check of the gate and retry; the actual mapped file and worker weren't used.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-12-01 17:49 UTC · original

Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree.

Base 5fabb46eaf6ed8771321787f8871051abde69b9b, head d1b74a6516166c70d36b7bf701025592b913d0d1. git diff --numstat → crates/victory-gpu/src/pipeline/library.rs 133/12.

All five test names are new on the base — git grep -F <name> 5fabb46e -- . → no match, exit 1 for each: library_trim_mode_parses_the_switch, library_trim_never_has_no_gate, library_trim_always_rearms_after_each_burst, library_trim_once_trims_after_the_first_burst_only, library_trim_gate_freed_when_the_worker_does_not_start.

git diff --check "5fabb46e..d1b74a65" → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4920'
cargo test --locked -p victory-gpu --lib -- pipeline::library::tests::<name> --exact --test-threads=1 --quiet

Each of the five: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1165 filtered out.

What they pin, all through the extracted pure helpers rather than the trim thread:

  • TrimMode::parse: None, "always" and any unrecognised value → Always; " once " (whitespace trimmed) → Once; "0" → Never.
  • Never returns no gate at all.
  • Always re-arms per burst: claim_trim with now=1500, loaded_at=1000, quiet=1000 is false because only 500 ms have passed; at now=2000 it is true; at 9000 the same burst's gate is spent, and only a fresh load re-arms it for 11000.
  • Once takes the gate for the whole run, so a load while the worker runs re-arms the burst gate but cannot let a second trim through, even 21 s later.
  • A worker that does not start frees the gate.

All values are synthetic timestamps and three AtomicBools; no pipeline file, no device. Worth flagging for the reviewer: this covers the gate/claim helpers only — the call sites that invoke them from the load path and the trim worker are not exercised here.

GPU/driver N/A. No game data.

**@⁠cloph-dsp** on GitHub · 2026-12-01 17:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4920#issuecomment-7319903317) Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree. Base `5fabb46eaf6ed8771321787f8871051abde69b9b`, head `d1b74a6516166c70d36b7bf701025592b913d0d1`. `git diff --numstat` → crates/victory-gpu/src/pipeline/library.rs 133/12. All five test names are new on the base — `git grep -F <name> 5fabb46e -- .` → no match, exit 1 for each: library_trim_mode_parses_the_switch, library_trim_never_has_no_gate, library_trim_always_rearms_after_each_burst, library_trim_once_trims_after_the_first_burst_only, library_trim_gate_freed_when_the_worker_does_not_start. `git diff --check "5fabb46e..d1b74a65"` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4920' cargo test --locked -p victory-gpu --lib -- pipeline::library::tests::<name> --exact --test-threads=1 --quiet ``` Each of the five: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1165 filtered out`. What they pin, all through the extracted pure helpers rather than the trim thread: - `TrimMode::parse`: None, "always" and any unrecognised value → Always; " once " (whitespace trimmed) → Once; "0" → Never. - Never returns no gate at all. - Always re-arms per burst: `claim_trim` with now=1500, loaded_at=1000, quiet=1000 is false because only 500 ms have passed; at now=2000 it is true; at 9000 the same burst's gate is spent, and only a fresh load re-arms it for 11000. - Once takes the gate for the whole run, so a load while the worker runs re-arms the burst gate but cannot let a second trim through, even 21 s later. - A worker that does not start frees the gate. All values are synthetic timestamps and three AtomicBools; no pipeline file, no device. Worth flagging for the reviewer: this covers the gate/claim helpers only — the call sites that invoke them from the load path and the trim worker are not exercised here. GPU/driver N/A. No game data.
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 origin '+refs/pull/4921/head:github-bot/gh-4920'
git switch 'github-bot/gh-4920'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4920'
git switch 'github-bot/gh-4920'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4920'
git switch 'github-bot/gh-4920'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4920'
git switch 'main'
git merge --squash 'github-bot/gh-4920'
git switch 'main'
git merge --ff-only 'github-bot/gh-4920'
git switch 'main'
git merge 'github-bot/gh-4920'
git push origin 'main'
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!4921
No description provided.