perf(cache): coalesce identical concurrent cache misses with self-cle… #1607

Merged
VlREX merged 1 commit from upstream-pr/1607 into main 2026-11-29 08:16:55 +00:00
VlREX commented 2026-11-28 22:17:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by VlREX on 2026-11-28T22:17:57Z.


What it changes

VIREX SINGLEFLIGHT eliminates redundant concurrent conversions of identical cache entries using independent per-key synchronization and automatic gate cleanup.

How it was tested

VIREX Test Studio 3.1.0 — PASS

  • Commit: ca35e799
  • CPU: Ryzen 5 3600X
  • GPU: Radeon RX 9070 GRE
  • OS: Windows 10 Pro
  • Workspace compilation: PASS
  • 32-worker concurrency test: PASS 3/3
  • Independent cache gates: PASS
  • Failure recovery: PASS
  • Full victory-pipeline unit test suite: 10/10 PASS

All 15 unit test executions passed.

Performance impact

Eliminates duplicate conversions for simultaneous identical cache misses within one process. Actual performance and memory savings require separate benchmarking.

No gameplay FPS improvement claimed.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5545115453 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1607). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-28T22:17:57Z. --- ## What it changes VIREX SINGLEFLIGHT eliminates redundant concurrent conversions of identical cache entries using independent per-key synchronization and automatic gate cleanup. ## How it was tested **VIREX Test Studio 3.1.0 — PASS** - Commit: `ca35e799` - CPU: Ryzen 5 3600X - GPU: Radeon RX 9070 GRE - OS: Windows 10 Pro - Workspace compilation: PASS - 32-worker concurrency test: PASS 3/3 - Independent cache gates: PASS - Failure recovery: PASS - Full victory-pipeline unit test suite: 10/10 PASS All 15 unit test executions passed. ## Performance impact Eliminates duplicate conversions for simultaneous identical cache misses within one process. Actual performance and memory savings require separate benchmarking. No gameplay FPS improvement claimed.
babuakhil commented 2026-11-28 23:08:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by babuakhil on 2026-11-28T23:08:50Z.


Checked on Windows 11 (Rust 1.98.1, pinned), applied on main (d4b5d51): clippy on victory-pipeline is clean with and without --all-features, and the 10 lib tests pass, 5 of 5 runs.

It does what it says. A throwaway stress test (not part of this PR): each round, 16 threads, each with its own Cache on the same root, ask for one new entry at once; every round also checks the published bytes and that no staging file is left.

scenario (rounds) main this PR
4 readers using std::fs::read (200) 3200 ok, 16.0 conversions/round 3200 ok, 1.0/round
4 readers holding the file without FILE_SHARE_DELETE (200) 1167 of 3200 fail with Access is denied. (os error 5) 3200 ok, 1.0/round
20 ms conversion (30) slowest round 48.6 ms, 16.0/round 34.1 ms, 1.0/round

The second row is the race #1539 fixes, and here it goes away too, since only one thread in the process publishes each entry. #1539 is still needed across processes (two victory runs, or warm beside a game).

One behaviour change worth knowing: when the conversion fails, the waiters no longer fail together. Each one takes the gate in turn, finds no file, and converts again:

failing 20 ms conversion, 16 threads (10 rounds) main this PR
conversions per round 16 16
slowest round 24.9 ms 331.6 ms

So a key whose conversion fails costs N × conversion time instead of about one. failed_conversion_releases_gate_for_retry covers a sequential retry, not this. If that matters, waiters could share the leader's error, or a waiter could return the error instead of converting when it wakes behind a failure. Not a blocker for the success path.

With #1539: the two apply together cleanly (both commits of #1539 on top of this), the 12 lib tests pass, and the same stress gives the same numbers as this PR alone (1.0 conversions/round, no errors; failing rounds 332.0 ms).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7247231457 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1607#issuecomment-7247231457). Originally posted by [babuakhil](https://github.com/babuakhil) on 2026-11-28T23:08:50Z. --- Checked on Windows 11 (Rust 1.98.1, pinned), applied on `main` (`d4b5d51`): clippy on `victory-pipeline` is clean with and without `--all-features`, and the 10 lib tests pass, 5 of 5 runs. **It does what it says.** A throwaway stress test (not part of this PR): each round, 16 threads, each with its own `Cache` on the same root, ask for one new entry at once; every round also checks the published bytes and that no staging file is left. | scenario (rounds) | `main` | this PR | |---|---|---| | 4 readers using `std::fs::read` (200) | 3200 ok, **16.0 conversions/round** | 3200 ok, **1.0/round** | | 4 readers holding the file without `FILE_SHARE_DELETE` (200) | 1167 of 3200 fail with `Access is denied. (os error 5)` | 3200 ok, 1.0/round | | 20 ms conversion (30) | slowest round 48.6 ms, 16.0/round | 34.1 ms, 1.0/round | The second row is the race #1539 fixes, and here it goes away too, since only one thread in the process publishes each entry. #1539 is still needed across processes (two `victory` runs, or `warm` beside a game). **One behaviour change worth knowing:** when the conversion **fails**, the waiters no longer fail together. Each one takes the gate in turn, finds no file, and converts again: | failing 20 ms conversion, 16 threads (10 rounds) | `main` | this PR | |---|---|---| | conversions per round | 16 | 16 | | slowest round | 24.9 ms | **331.6 ms** | So a key whose conversion fails costs N × conversion time instead of about one. `failed_conversion_releases_gate_for_retry` covers a sequential retry, not this. If that matters, waiters could share the leader's error, or a waiter could return the error instead of converting when it wakes behind a failure. Not a blocker for the success path. **With #1539:** the two apply together cleanly (both commits of #1539 on top of this), the 12 lib tests pass, and the same stress gives the same numbers as this PR alone (1.0 conversions/round, no errors; failing rounds 332.0 ms).
ArturoWolff commented 2026-11-29 08:53:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-29T08:53:56Z.


Follow-up on the merged integration. Thanks for #1607's per-key flight (ca35e799) and #1489's direct decoded-cache read and in-memory result on publication failure (4fd7f4db). On combined main, the two implementations interact: victory_gpu::shader_cache::cached reads and decodes directly, then calls Cache::convert_and_store, which does not acquire the existing get_or_convert flight. The general-purpose cache's original concurrency tests still pass, but the actual shader-cache helper can duplicate work.

I added two deterministic game-free tests with authored synthetic HostShader fixtures through the actual cache helper, synchronizing at the cold-miss boundary. Under GE-Proton11-14 / Linux, pinned Rust 1.98.1, locked MSVC library tests:

Check Combined base 4d98ca87 Local candidate on 829188e9
same-key overlapping calls FAIL: callback count 2, expected 1 PASS: count 1
different keys, second finishes while first is blocked PASS PASS
returned/persisted fixture equality and subsequent warm hits checked by both fixtures PASS

The two cache source files are identical between those base revisions. The fix is a small extension of the existing design: expose a closure-scoped per-key gate in victory-pipeline, preserve ungated validated hits, recheck decoded validity under that gate and only translate if still needed. Retain the in-memory result even when publication fails or the cache root cannot be canonicalized; do not change the shader serialization, fingerprint, or atomic publication rules. This is not a replacement for the separate cross-process publication work in #1539 / #632.

Validation on the local candidate: native pipeline package 13 passed, locked MSVC test build succeeded; 2/2 concurrency regressions and 3/3 additional game-free cache controls passed under isolated Wine (warm/corruption/unsupported, failed publication, missing root). An independent read-only review found no correctness blocker in the exact two-file diff. Full workspace CI, native Windows execution, actual startup-time and gameplay performance have not been validated. Same-key failed conversions or unsuccessful publication can still serialize later callers, as noted in the prior review of #1607; no failure-sharing or retry loop was added. No FPS or physical RAM savings claim.

I have the reviewed patch and reproducible tests retained and can submit the focused follow-up for review. This is intended to preserve both merged changes rather than replace either one.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253403494 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1607#issuecomment-7253403494). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T08:53:56Z. --- **Follow-up on the merged integration.** Thanks for #1607's per-key flight (`ca35e799`) and #1489's direct decoded-cache read and in-memory result on publication failure (`4fd7f4db`). On combined main, the two implementations interact: `victory_gpu::shader_cache::cached` reads and decodes directly, then calls `Cache::convert_and_store`, which does not acquire the existing `get_or_convert` flight. The general-purpose cache's original concurrency tests still pass, but the actual shader-cache helper can duplicate work. I added two deterministic game-free tests with authored synthetic `HostShader` fixtures through the actual cache helper, synchronizing at the cold-miss boundary. Under GE-Proton11-14 / Linux, pinned Rust 1.98.1, locked MSVC library tests: | Check | Combined base `4d98ca87` | Local candidate on `829188e9` | | --- | --- | --- | | same-key overlapping calls | FAIL: callback count 2, expected 1 | PASS: count 1 | | different keys, second finishes while first is blocked | PASS | PASS | | returned/persisted fixture equality and subsequent warm hits | checked by both fixtures | PASS | The two cache source files are identical between those base revisions. The fix is a small extension of the existing design: expose a closure-scoped per-key gate in `victory-pipeline`, preserve ungated validated hits, recheck decoded validity under that gate and only translate if still needed. Retain the in-memory result even when publication fails or the cache root cannot be canonicalized; do not change the shader serialization, fingerprint, or atomic publication rules. This is not a replacement for the separate cross-process publication work in #1539 / #632. Validation on the local candidate: native pipeline package **13 passed**, locked MSVC test build succeeded; **2/2** concurrency regressions and **3/3** additional game-free cache controls passed under isolated Wine (warm/corruption/unsupported, failed publication, missing root). An independent read-only review found no correctness blocker in the exact two-file diff. Full workspace CI, native Windows execution, actual startup-time and gameplay performance have not been validated. Same-key failed conversions or unsuccessful publication can still serialize later callers, as noted in the prior review of #1607; no failure-sharing or retry loop was added. No FPS or physical RAM savings claim. I have the reviewed patch and reproducible tests retained and can submit the focused follow-up for review. This is intended to preserve both merged changes rather than replace either one. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!1607
No description provided.