perf(victory-gpu): cache shader_cache build key per fingerprint and skip disk re-read on miss #406

Closed
github-bot wants to merge 1 commit from github-bot/gh-406 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:38 UTC · original
Lewandox:perf/shader-cache-avoid-rehash-and-reread → main · +70 −15 · 1 files · 1 commits · closed without merging

Summary

Eliminates repeated BLAKE3 re-hashing of shader_cache.rs on every lookup and avoids redundant disk re-reads/re-decodes on cache misses (third_party/victory/crates/victory-gpu/src/shader_cache.rs):

  1. Cache build() key per translation_fingerprint() (100% bit-identical key):
    • Previously build() re-hashed include_bytes!("shader_cache.rs") (~15 KiB) with BLAKE3 on every single shader cache lookup (thousands of shaders at startup and on every reload with VICTORY_DROP_DXIL=1).
    • Now caches the computed [u8; 32] key against the last translation_fingerprint() so lookups reuse the exact same BLAKE3 key in O(1) while still immediately recomputing if the device probe changes the fingerprint (preserving 100% on-disk cache compatibility).
  2. Avoid disk re-read & re-decode on cache miss:
    • Previously, after Translate::convert() translated a shader and wrote the encoded entry to disk, cached() immediately called std::fs::read(&path) and decode(&b), reading the file back from disk and allocating a duplicate HostShader + dxil buffer.
    • Translate now retains the freshly produced HostShader so cached() returns it directly on a miss while keeping the exact on-disk write and hit/corrupt-recovery paths unchanged.
  3. Pre-size encode() buffer:
    • Computes the exact encoded byte length upfront (Vec::with_capacity) instead of growing from 4 bytes through repeated reallocations.
  4. Unit tests:
    • Verifies build_for returns the exact same hash as full recomputation and updates immediately when translation_fingerprint changes.
    • Verifies encode allocates the exact serialized size without spare reallocations, and all existing round-trip / corrupt-cache-recovery tests continue to pass.

Verification

  • cargo test -p victory-gpu --lib shader_cache::tests (default and --features diagnostics)
  • cargo xtask policy inside third_party/victory
**@⁠Lewandox** on GitHub · 2026-11-26 17:38 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/406) `Lewandox:perf/shader-cache-avoid-rehash-and-reread` → `main` · +70 −15 · 1 files · 1 commits · closed without merging ## Summary Eliminates repeated BLAKE3 re-hashing of `shader_cache.rs` on every lookup and avoids redundant disk re-reads/re-decodes on cache misses (`third_party/victory/crates/victory-gpu/src/shader_cache.rs`): 1. **Cache `build()` key per `translation_fingerprint()` (100% bit-identical key)**: - Previously `build()` re-hashed `include_bytes!("shader_cache.rs")` (~15 KiB) with BLAKE3 on every single shader cache lookup (thousands of shaders at startup and on every reload with `VICTORY_DROP_DXIL=1`). - Now caches the computed `[u8; 32]` key against the last `translation_fingerprint()` so lookups reuse the exact same BLAKE3 key in O(1) while still immediately recomputing if the device probe changes the fingerprint (preserving 100% on-disk cache compatibility). 2. **Avoid disk re-read & re-decode on cache miss**: - Previously, after `Translate::convert()` translated a shader and wrote the encoded entry to disk, `cached()` immediately called `std::fs::read(&path)` and `decode(&b)`, reading the file back from disk and allocating a duplicate `HostShader` + `dxil` buffer. - `Translate` now retains the freshly produced `HostShader` so `cached()` returns it directly on a miss while keeping the exact on-disk write and hit/corrupt-recovery paths unchanged. 3. **Pre-size `encode()` buffer**: - Computes the exact encoded byte length upfront (`Vec::with_capacity`) instead of growing from 4 bytes through repeated reallocations. 4. **Unit tests**: - Verifies `build_for` returns the exact same hash as full recomputation and updates immediately when `translation_fingerprint` changes. - Verifies `encode` allocates the exact serialized size without spare reallocations, and all existing round-trip / corrupt-cache-recovery tests continue to pass. ## Verification - `cargo test -p victory-gpu --lib shader_cache::tests` (default and `--features diagnostics`) - `cargo xtask policy` inside `third_party/victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:41:52 +00:00
github-bot force-pushed github-bot/gh-406 from 977a36ca3f to 28f5f9e444 2026-11-26 19:34:59 +00:00 Compare
github-bot force-pushed github-bot/gh-406 from 28f5f9e444 to 233dcf3d38 2026-11-27 00:36:10 +00:00 Compare
github-bot closed this pull request 2026-11-27 00:36:11 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:09 UTC · original

Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

Vice-Tay already keeps translated shaders in memory instead of re-reading the disk on a miss; the rest (hashing the key per lookup) came without a measurement.

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

**@⁠LooperSalty** on GitHub · 2026-11-26 23:09 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/406#issuecomment-7205299048) Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). Vice-Tay already keeps translated shaders in memory instead of re-reading the disk on a miss; the rest (hashing the key per lookup) came without a measurement. Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.