Pipelines: the slow list counts only compiles; the pipeline library can be read ahead (VICTORY_LIBRARY_PREFETCH=1) #443

Open
github-bot wants to merge 1 commit from github-bot/gh-443 into main AGit
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 08:28 UTC · original
Jesper-Andersson:pipeline-prefetch → main · +329 −13 · 2 files · 1 commits · open

Fixes #442.

slow-pipelines.txt is meant for compiles that hold a worker for tens of seconds, but library::note_time (crates/victory-gpu/src/pipeline/library.rs:741-752, called from Pending::make in pipeline/make.rs:91) times the whole HostPipeline::new, so a load from the pipeline library that takes a second goes on the list too. That happens often: on a SATA disk, while the title streams, a load can fault in cold pages of the mapped library. Nothing ever comes off the list, either. In one cache here the list held 1,817 of 3,224 early keys, many of them pipelines the library had. Queue::push sends every listed early pipeline to Queue::slow, where at most a quarter of the workers (slow_limit) take them, after all the others. So pipelines that would load in milliseconds waited in a queue meant for long compiles, and a large share of the early pipelines were still not made when the world began to draw.

Change

  • The slow list counts only compiles (library::note_time, slow_change, compiles_only). A make now knows how it came about: library::came_of runs it and reads what the library calls on its thread did (Came::Loaded, Compiled, or Nothing for a refusal or a pipeline on the bad list), keeping the most telling one. A compile of 1 s or more adds the key (or raises its time), as before. A compile under 1 s takes the key off. A load does neither. This is a fix of what is counted, so it is on by default; VICTORY_PIPELINE_SLOW_LIST=0 restores the old rule (any make of a second is added, nothing removed). Lists that already hold load-made keys lose them as those pipelines are compiled again (a new driver, a rejected library). A key whose pipeline only ever loads stays on until then, but no new ones are added.
  • VICTORY_LIBRARY_PREFETCH=1 (off by default) reads the mapped library ahead (library::prefetch, called from open when the blob is a mapped file). A thread of its own, in background mode (THREAD_MODE_BACKGROUND_BEGIN: lowest CPU, I/O and memory priority), calls PrefetchVirtualMemory over the view, 64 MB at a time (prefetch_part). It checks free physical memory before each part and stops below 6 GB. Per the API's remarks, the pages go to the system file cache (standby list), not to the process's working set or private bytes. The early loads then find them there instead of faulting them in one at a time. It logs host pipeline library read ahead (VICTORY_LIBRARY_PREFETCH) with the bytes, the time taken and the free memory at the end.
  • A log line, early pipelines all made, is written each time the early pipelines started at creation (make::early) are all made (at least 10 more since the last line). It gives the count loaded, compiled and neither, slow_queued, slow_list_added/removed and ms_since_first_early. This is the number to compare.

Where it does nothing

  • VICTORY_PIPELINE_SLOW=0 (no slow queue): the list is still kept, but nothing reads it.
  • No library, or an empty or rejected one: every make is a compile, so the list behaves as before except that quick compiles now take a key off.
  • A library read into memory instead of mapped: no read-ahead (nothing to fault in).
  • Tests: the_slow_list_counts_compiles_only, a_slow_key_that_compiles_quickly_comes_off_the_list, came_of_tells_the_most_telling_call, the_read_ahead_goes_in_parts_while_memory_is_free, early_pipelines_are_counted_once_by_how_they_came.

Measured

These numbers come from a local branch, not from main: main plus about 50 merged PRs, with this change (and an experimental third switch, VICTORY_PIPELINE_SLOW_LOAD_FIRST, left out of this PR because both runs with it alone crashed in the menus). All runs used the same exe and the same unattended scripted route from start to world entry. Machine: RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, game and cache on a SATA QLC SSD. Diag build, Xbox Series S profile, DLSS upscaling.

without read-ahead VICTORY_LIBRARY_PREFETCH=1
early pipelines still not made at world entry 736, 987, 802, 0 (4 runs) 0 in 6 of 6 runs (2 of them also with SLOW_LOAD_FIRST=1)
time until all early pipelines were made (one interleaved pair) 75 s 34 s
read-ahead of the 981 MB library - 33-55 ms

The read-ahead took only 33-55 ms because the file was already in the OS file cache. So the gain is not disk reads saved. It comes from the process's own page faults on the mapping during loading, which the prefetch takes out of the loads' path.

What it does not fix: the first run after a rebuild (new shaders, so the library misses) without victory warm --used still has a backlog, because the driver has to compile those pipelines. The read-ahead only helps pipelines the library has.

Checks

  • cargo test --locked -p victory-gpu --lib pipeline: 31 passed (5 new)
  • cargo clippy --locked -p victory-gpu --all-targets: no warnings in the changed files (4 warnings already on main in list.rs, host/panel.rs, host/place.rs, watch.rs)
  • cargo xtask policy --staged (pre-commit hook): 2 files ok
  • In game: the runs above were on the local branch; this rebased commit on main has not been run in game.

Not checked

  • AMD cards, Linux/Proton, NVMe disks, and PCs with 16 GB or less (the 6 GB floor stops the read-ahead early there).
  • A cold OS file cache (just after a reboot), where the read-ahead also has to read the disk. That is the case where it could help most, or compete most with the title's own streaming.
  • The most useful check: two runs each way from a reboot, comparing ms_since_first_early in the early pipelines all made line and the pipelines still waiting at world entry.
  • No open or closed PR found here, or in the forks searched (Marvisak/VIctory, fxceless/victory-fork, pr0vId3nce/VIctory-NVIDIA, trustno1-coder/VIctory-NVIDIA), that changes what the slow list counts or reads the library ahead.
  • #164 (VICTORY_PIPELINE_LOW_MEMORY=1) also schedules slow-listed pipelines, at first use and for screen passes. It does not change what goes on the list, so the two fit together.
  • Marvisak/VIctory#3432 and #3430 map and trim the library file, and #3296 is the slow queue that main has. None of them reads the library ahead.

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

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 08:28 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/443) `Jesper-Andersson:pipeline-prefetch` → `main` · +329 −13 · 2 files · 1 commits · open Fixes #442. `slow-pipelines.txt` is meant for compiles that hold a worker for tens of seconds, but `library::note_time` (`crates/victory-gpu/src/pipeline/library.rs:741-752`, called from `Pending::make` in `pipeline/make.rs:91`) times the whole `HostPipeline::new`, so a **load** from the pipeline library that takes a second goes on the list too. That happens often: on a SATA disk, while the title streams, a load can fault in cold pages of the mapped library. Nothing ever comes off the list, either. In one cache here the list held 1,817 of 3,224 early keys, many of them pipelines the library had. `Queue::push` sends every listed early pipeline to `Queue::slow`, where at most a quarter of the workers (`slow_limit`) take them, after all the others. So pipelines that would load in milliseconds waited in a queue meant for long compiles, and a large share of the early pipelines were still not made when the world began to draw. ## Change - **The slow list counts only compiles** (`library::note_time`, `slow_change`, `compiles_only`). A make now knows how it came about: `library::came_of` runs it and reads what the library calls on its thread did (`Came::Loaded`, `Compiled`, or `Nothing` for a refusal or a pipeline on the bad list), keeping the most telling one. A compile of 1 s or more adds the key (or raises its time), as before. A compile under 1 s takes the key off. A load does neither. This is a fix of what is counted, so it is on by default; `VICTORY_PIPELINE_SLOW_LIST=0` restores the old rule (any make of a second is added, nothing removed). Lists that already hold load-made keys lose them as those pipelines are compiled again (a new driver, a rejected library). A key whose pipeline only ever loads stays on until then, but no new ones are added. - **`VICTORY_LIBRARY_PREFETCH=1` (off by default) reads the mapped library ahead** (`library::prefetch`, called from `open` when the blob is a mapped file). A thread of its own, in background mode (`THREAD_MODE_BACKGROUND_BEGIN`: lowest CPU, I/O and memory priority), calls `PrefetchVirtualMemory` over the view, 64 MB at a time (`prefetch_part`). It checks free physical memory before each part and stops below 6 GB. Per the API's remarks, the pages go to the system file cache (standby list), not to the process's working set or private bytes. The early loads then find them there instead of faulting them in one at a time. It logs `host pipeline library read ahead (VICTORY_LIBRARY_PREFETCH)` with the bytes, the time taken and the free memory at the end. - **A log line**, `early pipelines all made`, is written each time the early pipelines started at creation (`make::early`) are all made (at least 10 more since the last line). It gives the count loaded, compiled and neither, `slow_queued`, `slow_list_added`/`removed` and `ms_since_first_early`. This is the number to compare. ## Where it does nothing - `VICTORY_PIPELINE_SLOW=0` (no slow queue): the list is still kept, but nothing reads it. - No library, or an empty or rejected one: every make is a compile, so the list behaves as before except that quick compiles now take a key off. - A library read into memory instead of mapped: no read-ahead (nothing to fault in). - Tests: `the_slow_list_counts_compiles_only`, `a_slow_key_that_compiles_quickly_comes_off_the_list`, `came_of_tells_the_most_telling_call`, `the_read_ahead_goes_in_parts_while_memory_is_free`, `early_pipelines_are_counted_once_by_how_they_came`. ## Measured These numbers come from a **local branch, not from main**: main plus about 50 merged PRs, with this change (and an experimental third switch, `VICTORY_PIPELINE_SLOW_LOAD_FIRST`, left out of this PR because both runs with it alone crashed in the menus). All runs used the same exe and the same unattended scripted route from start to world entry. Machine: RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, game and cache on a SATA QLC SSD. Diag build, Xbox Series S profile, DLSS upscaling. | | without read-ahead | `VICTORY_LIBRARY_PREFETCH=1` | |---|---|---| | early pipelines still not made at world entry | 736, 987, 802, 0 (4 runs) | 0 in 6 of 6 runs (2 of them also with `SLOW_LOAD_FIRST=1`) | | time until all early pipelines were made (one interleaved pair) | 75 s | 34 s | | read-ahead of the 981 MB library | - | 33-55 ms | The read-ahead took only 33-55 ms because the file was already in the OS file cache. So the gain is not disk reads saved. It comes from the process's own page faults on the mapping during loading, which the prefetch takes out of the loads' path. What it does not fix: the first run after a rebuild (new shaders, so the library misses) without `victory warm --used` still has a backlog, because the driver has to compile those pipelines. The read-ahead only helps pipelines the library has. ## Checks - `cargo test --locked -p victory-gpu --lib pipeline`: 31 passed (5 new) - `cargo clippy --locked -p victory-gpu --all-targets`: no warnings in the changed files (4 warnings already on main in `list.rs`, `host/panel.rs`, `host/place.rs`, `watch.rs`) - `cargo xtask policy --staged` (pre-commit hook): 2 files ok - In game: the runs above were on the local branch; this rebased commit on main has not been run in game. ## Not checked - AMD cards, Linux/Proton, NVMe disks, and PCs with 16 GB or less (the 6 GB floor stops the read-ahead early there). - A cold OS file cache (just after a reboot), where the read-ahead also has to read the disk. That is the case where it could help most, or compete most with the title's own streaming. - The most useful check: two runs each way from a reboot, comparing `ms_since_first_early` in the `early pipelines all made` line and the pipelines still waiting at world entry. ## Related - No open or closed PR found here, or in the forks searched (Marvisak/VIctory, fxceless/victory-fork, pr0vId3nce/VIctory-NVIDIA, trustno1-coder/VIctory-NVIDIA), that changes what the slow list counts or reads the library ahead. - #164 (`VICTORY_PIPELINE_LOW_MEMORY=1`) also schedules slow-listed pipelines, at first use and for screen passes. It does not change what goes on the list, so the two fit together. - Marvisak/VIctory#3432 and #3430 map and trim the library file, and #3296 is the slow queue that main has. None of them reads the library ahead. This change was made with AI assistance (Claude Code).
Any make of a second went on slow-pipelines.txt, library loads too (a
cold page of the mapped library on a SATA disk while the title streams),
and nothing came off: 1,817 of 3,224 early keys were on it in one cache,
and they waited behind all the others in the slow queue though the
library had them.

- VICTORY_PIPELINE_SLOW_LIST (on; =0 as before): only a compile adds a key
  (>= 1 s) or takes it off (< 1 s); a load from the library does neither.
  How a make came about is told by the library calls on its thread
  (library::came_of).
- VICTORY_LIBRARY_PREFETCH=1 (off): PrefetchVirtualMemory over the mapped
  library at its opening, on a background-mode thread, 64 MB at a time,
  stopping below 6 GB of free physical memory.
- Log line "early pipelines all made": loaded, compiled, neither,
  slow_queued, slow_list_added/removed, ms_since_first_early.

This change was made with AI assistance (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:32:02 +00:00
This pull request can be merged automatically.
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/443/head:github-bot/gh-443'
git switch 'github-bot/gh-443'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'main'
git merge --squash 'github-bot/gh-443'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'main'
git merge 'github-bot/gh-443'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.