perf(victory-gpu): speed up known-pipeline boot prefetch and loose-part deserialize #11

Manually merged
github merged 1 commit from github-bot/gh-11 into mega-upgrade-v3 2026-12-04 20:20:06 +00:00 AGit
Owner

@⁠MahanYTT on GitHub · 2026-12-04 18:27 UTC · original
MahanYTT:perf/pipeline-boot-and-loose-parts → mega-upgrade-v3 · +568 −128 · 7 files · 1 commits · merged 2026-12-04 20:18 UTC

Root Causes Addressed

  1. Known-pipeline book loading & prefetch stall (pipeline/known.rs, pipeline/make.rs, pipeline.rs):
    • walk_shaders used an 8 KiB BufReader over 19,117 shader containers (~38k syscalls per scan); bumped to 256 KiB for both walk_shaders and walk_pipelines.
    • known::recipes formatted 16-byte keys into String via 16× format!("{b:02x}") across all 89,320 pipelines (~1.52M heap allocations) and buffered all 4,999 recipes before starting a single worker. Now pre-parses wanted into HashSet<[u8; 16]>, stops scanning early once all wanted IDs are found, and streams recipes directly to make::prefetch in batches of 32 (Queue::push_prefetch_batch) under single PREFETCHED and QUEUE locks.
    • known::recipes/make/names re-read, zlib-decompressed, re-hashed (blake3), and cloned shared shader containers for every pipeline reference. Added Shader::full_hash, shader_cached, shader_from_owned, and ShaderResolver so each unique shader is read, decompressed, and interned at most once.
    • known::note serialized GraphicsState (g.put) into a Vec<u8> on the title thread before checking Book::keys.contains(&id). Added Book::note_graphics to skip serialization for already-known IDs, reused shader.full_hash in Book::note, and moved keys/shaders in O(1) in Book::read when empty.
    • Eliminated redundant CString clones in GraphicsState::get.
  2. Startup lock contention (pipeline.rs, pipeline/library.rs):
    • Converted SHADERS, USED, and SLOW from Mutex to RwLock, with read-first checks on shader(), wanted_early(), note_used(), slow(), slow_ms(), and note_time().
  3. Loose-part Deserialize*PipelineStateX overhead (device.rs):
    • Cached VICTORY_DESERIALIZE_DUMP in a OnceLock instead of calling std::env::var_os on every call (18k+ calls).
    • Replaced repeated power-of-two detailed WARN logs (each performing kernel ReadProcessMemory reads, loose_metadata/loose_compute/deserialize_parts parsing, and 6,144 hex format! allocations up to 16,384 calls) with loose_log_mode: one detailed WARN on call 1 (using single-allocation hex_preview, and skipping loose_compute unless VICTORY_LOOSE_PIPELINES=1) and lightweight count-only DEBUG summaries on powers of two ≥ 64.

Verification

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --tests -- -D warnings: 0 warnings, 0 errors (including all pipeline/make.rs deferral tests).
  • cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --features diagnostics --tests -- -D warnings: 0 warnings, 0 errors.
  • Added focused unit tests in device.rs, pipeline.rs, pipeline/known.rs, and pipeline/make.rs, and executed standalone rustc --test verification of the new pure-Rust helpers.
**@⁠MahanYTT** on GitHub · 2026-12-04 18:27 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/11) `MahanYTT:perf/pipeline-boot-and-loose-parts` → `mega-upgrade-v3` · +568 −128 · 7 files · 1 commits · merged 2026-12-04 20:18 UTC ### Root Causes Addressed 1. **Known-pipeline book loading & prefetch stall (`pipeline/known.rs`, `pipeline/make.rs`, `pipeline.rs`)**: - `walk_shaders` used an 8 KiB `BufReader` over 19,117 shader containers (~38k syscalls per scan); bumped to 256 KiB for both `walk_shaders` and `walk_pipelines`. - `known::recipes` formatted 16-byte keys into `String` via 16× `format!("{b:02x}")` across all 89,320 pipelines (~1.52M heap allocations) and buffered all 4,999 recipes before starting a single worker. Now pre-parses `wanted` into `HashSet<[u8; 16]>`, stops scanning early once all wanted IDs are found, and streams recipes directly to `make::prefetch` in batches of 32 (`Queue::push_prefetch_batch`) under single `PREFETCHED` and `QUEUE` locks. - `known::recipes`/`make`/`names` re-read, zlib-decompressed, re-hashed (`blake3`), and cloned shared shader containers for every pipeline reference. Added `Shader::full_hash`, `shader_cached`, `shader_from_owned`, and `ShaderResolver` so each unique shader is read, decompressed, and interned at most once. - `known::note` serialized `GraphicsState` (`g.put`) into a `Vec<u8>` on the title thread before checking `Book::keys.contains(&id)`. Added `Book::note_graphics` to skip serialization for already-known IDs, reused `shader.full_hash` in `Book::note`, and moved `keys`/`shaders` in O(1) in `Book::read` when empty. - Eliminated redundant `CString` clones in `GraphicsState::get`. 2. **Startup lock contention (`pipeline.rs`, `pipeline/library.rs`)**: - Converted `SHADERS`, `USED`, and `SLOW` from `Mutex` to `RwLock`, with read-first checks on `shader()`, `wanted_early()`, `note_used()`, `slow()`, `slow_ms()`, and `note_time()`. 3. **Loose-part `Deserialize*PipelineStateX` overhead (`device.rs`)**: - Cached `VICTORY_DESERIALIZE_DUMP` in a `OnceLock` instead of calling `std::env::var_os` on every call (18k+ calls). - Replaced repeated power-of-two detailed `WARN` logs (each performing kernel `ReadProcessMemory` reads, `loose_metadata`/`loose_compute`/`deserialize_parts` parsing, and 6,144 hex `format!` allocations up to 16,384 calls) with `loose_log_mode`: one detailed `WARN` on call 1 (using single-allocation `hex_preview`, and skipping `loose_compute` unless `VICTORY_LOOSE_PIPELINES=1`) and lightweight count-only `DEBUG` summaries on powers of two ≥ 64. ### Verification - `cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --tests -- -D warnings`: 0 warnings, 0 errors (including all `pipeline/make.rs` deferral tests). - `cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc --features diagnostics --tests -- -D warnings`: 0 warnings, 0 errors. - Added focused unit tests in `device.rs`, `pipeline.rs`, `pipeline/known.rs`, and `pipeline/make.rs`, and executed standalone `rustc --test` verification of the new pure-Rust helpers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:27:25 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:06 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.