perf(gpu): filter no-op refresh spans before ask_ahead and chunk wide_each #1133

Manually merged
github merged 1 commit from github-bot/gh-1133 into main 2026-11-29 08:21:46 +00:00 AGit
Owner

@⁠adwen-007 on GitHub · 2026-11-28 13:51 UTC · original
adwen-007:pr/perf-refresh-filter-wide-each → main · +40 −20 · 2 files · 1 commits · merged 2026-11-29 08:16 UTC

Problem

In draw-heavy scenes, Batch::flush frequently processes 500–2,000+ spans per flush (~7,000–9,000 per frame), of which ~85% are nothing_new. Because spans.len() > 256 skipped the pre-filter:

  1. All clean spans were passed into watch::ask_ahead(&ranges).
  2. All clean spans were dispatched across shadow::wide_each, hammering the shared atomic FLUSHES[2] cache line from every worker thread.
  3. shadow::wide_each claimed 1 index per fetch_add(1) across all worker threads and allocated Arc/Box/Vec even when n <= 1.

Fix

  • Always filter !shadow.nothing_new(...) before ask_ahead and wide_each in Batch::flush and Batch::refresh_ahead (crates/victory-gpu/src/host.rs), returning early if no dirty spans or textures remain.
  • Add an n <= 1 fast path and chunked dynamic claiming (chunk = (n / (threads * 8)).clamp(1, 16)) in shadow::wide_each (crates/victory-gpu/src/shadow.rs).

Verification

  • cargo check -p victory-gpu passes cleanly on v2026.11.28.01 (63b902f).
  • Verified in live title gameplay on i7-12700K + RTX 3060 Ti: spans dispatched to worker threads dropped ~70% (3,971 -> 1,119 per frame) with zero regressions.
**@⁠adwen-007** on GitHub · 2026-11-28 13:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1133) `adwen-007:pr/perf-refresh-filter-wide-each` → `main` · +40 −20 · 2 files · 1 commits · merged 2026-11-29 08:16 UTC ## Problem In draw-heavy scenes, `Batch::flush` frequently processes 500–2,000+ spans per flush (~7,000–9,000 per frame), of which ~85% are `nothing_new`. Because `spans.len() > 256` skipped the pre-filter: 1. All clean spans were passed into `watch::ask_ahead(&ranges)`. 2. All clean spans were dispatched across `shadow::wide_each`, hammering the shared atomic `FLUSHES[2]` cache line from every worker thread. 3. `shadow::wide_each` claimed 1 index per `fetch_add(1)` across all worker threads and allocated `Arc`/`Box`/`Vec` even when `n <= 1`. ## Fix - Always filter `!shadow.nothing_new(...)` before `ask_ahead` and `wide_each` in `Batch::flush` and `Batch::refresh_ahead` (`crates/victory-gpu/src/host.rs`), returning early if no dirty spans or textures remain. - Add an `n <= 1` fast path and chunked dynamic claiming (`chunk = (n / (threads * 8)).clamp(1, 16)`) in `shadow::wide_each` (`crates/victory-gpu/src/shadow.rs`). ## Verification - `cargo check -p victory-gpu` passes cleanly on `v2026.11.28.01` (`63b902f`). - Verified in live title gameplay on i7-12700K + RTX 3060 Ti: spans dispatched to worker threads dropped ~70% (`3,971 -> 1,119` per frame) with zero regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:33:58 +00:00
Author
Owner

@⁠urielbeaupre on GitHub · 2026-11-28 17:06 UTC · original

An A/B on top of other copy-path work, for the record. RTX 4070 Ti 12 GB, Ryzen 9 7900X, Series S profile, DLSS off, same save, warm caches.

Base: main 63b902f with #1038 and #1184 (lazy landing/fetch on). That base already removes most per-frame refresh and copy-back work on the 21 MB buffer. #697 and #1133 merged cleanly on top; VICTORY_ASK_HOLD_ALL=1 gives #1133 alone. Cutscene = 60–110 s after input, after = 110–165 s. Warm runs only (the new build's first run built pipelines and isn't counted):

cutscene fps after scene change CPU preparing (cutscene) copying per frame
base (2 runs) 38.0 / 40.1 24.9 / 25.0 20.6 / 19.3 ms 12.0 / 11.3 ms
+ #1133 (1 run) 38.4 23.8 21.1 ms 12.8 ms
+ #1133 + #697 (2 runs) 37.8 / 37.4 26.0 / 22.9 20.8 / 21.1 ms 11.7 / 14.2 ms

On this setup neither shows a gain. Both are within about ±1.5 fps of the base, which is run-to-run noise here, and with both the copying is about 1.3 ms higher on average. No errors, and draw counts match.

This doesn't say the PRs are wrong. Where most refresh spans are already nothing_new and the big buffer no longer goes round the CPU, there's little left for them to save. In heavy scenes on this machine, the submit thread's biggest cost now is the refreshes themselves: about 23 ms a frame over ~6,500 spans, of which ~5,200 copy nothing.

🤖 Generated with Claude Code

**@⁠urielbeaupre** on GitHub · 2026-11-28 17:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1133#issuecomment-7242759323) An A/B on top of other copy-path work, for the record. RTX 4070 Ti 12 GB, Ryzen 9 7900X, Series S profile, DLSS off, same save, warm caches. Base: main 63b902f with #1038 and #1184 (lazy landing/fetch on). That base already removes most per-frame refresh and copy-back work on the 21 MB buffer. #697 and #1133 merged cleanly on top; `VICTORY_ASK_HOLD_ALL=1` gives #1133 alone. Cutscene = 60–110 s after input, after = 110–165 s. Warm runs only (the new build's first run built pipelines and isn't counted): | | cutscene fps | after scene change | CPU preparing (cutscene) | copying per frame | |---|---|---|---|---| | base (2 runs) | 38.0 / 40.1 | 24.9 / 25.0 | 20.6 / 19.3 ms | 12.0 / 11.3 ms | | + #1133 (1 run) | 38.4 | 23.8 | 21.1 ms | 12.8 ms | | + #1133 + #697 (2 runs) | 37.8 / 37.4 | 26.0 / 22.9 | 20.8 / 21.1 ms | 11.7 / 14.2 ms | On this setup neither shows a gain. Both are within about ±1.5 fps of the base, which is run-to-run noise here, and with both the copying is about 1.3 ms higher on average. No errors, and draw counts match. This doesn't say the PRs are wrong. Where most refresh spans are already `nothing_new` and the big buffer no longer goes round the CPU, there's little left for them to save. In heavy scenes on this machine, the submit thread's biggest cost now is the refreshes themselves: about 23 ms a frame over ~6,500 spans, of which ~5,200 copy nothing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠timorjay on GitHub · 2026-11-28 17:07 UTC · original

Hardware follow-up at acc6df7d45 on an RTX 5090 D v2 and Ryzen 7 9800X3D. I compared Windows release builds on 63b902fe17, with #703 in every build. Each run started in a fresh, offline Windows Sandbox with the same save, Series S profile, RELAY=1, THIN=0, TEXTURE_POOL=0, DLSS and frame generation off. The host has 32 GB of RAM and the guest was configured for 20 GiB.

For each run I replayed the same 72 s of camera and movement inputs starting at the prologue cell window. The FPS column divides actual presents by elapsed time across complete frame-time log intervals, including stalls. The final camera position varied across runs.

Build Presents / measured time FPS Frames over 100 ms Spans reported on worker threads, median per frame CPU prepare, median
Baseline 891 / 71.30 s 12.50 5.84% 5,972 39.15 ms
+ this PR 934 / 70.92 s 13.17 4.82% 3,280 39.10 ms
+ indoor reflection hold (#818) 930 / 69.17 s 13.45 4.73% 6,746 35.45 ms
+ reflection hold and this PR 755 / 70.43 s 10.72 6.09% 3,486 42.05 ms

The patched runs report roughly half as many spans dispatched to workers in both comparisons. That counter reflects the change in which spans are dispatched. The median refresh times were 16.6 → 17.7 ms without the reflection hold and 15.5 → 18.9 ms with it. One run per configuration, unequal draw counts and cold caches leave the whole-frame effect unresolved on this hardware. The combined build also reached the city-memory shop and handled aiming inputs for the full 95 s observation.

Test automation and analysis assisted by Codex.

**@⁠timorjay** on GitHub · 2026-11-28 17:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1133#issuecomment-7242776404) Hardware follow-up at `acc6df7d45` on an RTX 5090 D v2 and Ryzen 7 9800X3D. I compared Windows release builds on `63b902fe17`, with #703 in every build. Each run started in a fresh, offline Windows Sandbox with the same save, Series S profile, `RELAY=1`, `THIN=0`, `TEXTURE_POOL=0`, DLSS and frame generation off. The host has 32 GB of RAM and the guest was configured for 20 GiB. For each run I replayed the same 72 s of camera and movement inputs starting at the prologue cell window. The FPS column divides actual presents by elapsed time across complete frame-time log intervals, including stalls. The final camera position varied across runs. | Build | Presents / measured time | FPS | Frames over 100 ms | Spans reported on worker threads, median per frame | CPU prepare, median | | --- | ---: | ---: | ---: | ---: | ---: | | Baseline | 891 / 71.30 s | 12.50 | 5.84% | 5,972 | 39.15 ms | | + this PR | 934 / 70.92 s | 13.17 | 4.82% | 3,280 | 39.10 ms | | + indoor reflection hold (#818) | 930 / 69.17 s | 13.45 | 4.73% | 6,746 | 35.45 ms | | + reflection hold and this PR | 755 / 70.43 s | 10.72 | 6.09% | 3,486 | 42.05 ms | The patched runs report roughly half as many spans dispatched to workers in both comparisons. That counter reflects the change in which spans are dispatched. The median refresh times were 16.6 → 17.7 ms without the reflection hold and 15.5 → 18.9 ms with it. One run per configuration, unequal draw counts and cold caches leave the whole-frame effect unresolved on this hardware. The combined build also reached the city-memory shop and handled aiming inputs for the full 95 s observation. Test automation and analysis assisted by Codex.
Author
Owner

@⁠unueberlegt on GitHub · 2026-11-29 01:23 UTC · original

Data point from an independent pass over the same problem (#1521's first point, measured standalone before I saw this): on our side the no-op filter stays parallel on the workers instead of serial on the submitting thread — each worker claims VICTORY_WIDE_CHUNK (we landed on 16 as the default, up from 1) spans at a time, takes one JOURNAL read guard per claim, and does one FLUSHES[2].fetch_add(noop) per claim, so the journal RMWs and the shared counter line drop by the chunk size. Filtered survivors then go to the copies per-index as before, and the filter runs after ask_ahead (inside the ahead-covered window), where the no-op answer is cheapest. Measured on RTX 5070 12 GB, Ryzen 9 9950X3D (16C/32T), Series X 2560x1440, prologue, steady windows, medians: refreshes 7.2 → 6.8 ms/frame against the unfiltered baseline (the flush wall time there is bounded by the ~16% real copies, so the win case is again the CPU-bound 8-core of the issue).

One thing to weigh in your version: nothing_new before ask_ahead answers from the previous submission's ahead window (or the published bits), so it filters less than a filter that runs inside the window — and the serial cost of ~7,000 spans on the submitting thread is the mill figure #1521 wants off that thread. The numbers above are with the filter parallel and inside the window, for comparison.

GPU and profile: NVIDIA RTX 5070 12 GB, AMD Ryzen 9 9950X3D, 31 GB RAM, Windows 11 26300; release builds, steady-window medians.

**@⁠unueberlegt** on GitHub · 2026-11-29 01:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1133#issuecomment-7248752587) Data point from an independent pass over the same problem (#1521's first point, measured standalone before I saw this): on our side the no-op filter stays parallel on the workers instead of serial on the submitting thread — each worker claims `VICTORY_WIDE_CHUNK` (we landed on 16 as the default, up from 1) spans at a time, takes **one** `JOURNAL` read guard per claim, and does one `FLUSHES[2].fetch_add(noop)` per claim, so the journal RMWs and the shared counter line drop by the chunk size. Filtered survivors then go to the copies per-index as before, and the filter runs **after** `ask_ahead` (inside the ahead-covered window), where the no-op answer is cheapest. Measured on RTX 5070 12 GB, Ryzen 9 9950X3D (16C/32T), Series X 2560x1440, prologue, steady windows, medians: refreshes 7.2 → 6.8 ms/frame against the unfiltered baseline (the flush wall time there is bounded by the ~16% real copies, so the win case is again the CPU-bound 8-core of the issue). One thing to weigh in your version: `nothing_new` before `ask_ahead` answers from the *previous* submission's ahead window (or the published bits), so it filters less than a filter that runs inside the window — and the serial cost of ~7,000 spans on the submitting thread is the mill figure #1521 wants off that thread. The numbers above are with the filter parallel and inside the window, for comparison. GPU and profile: NVIDIA RTX 5070 12 GB, AMD Ryzen 9 9950X3D, 31 GB RAM, Windows 11 26300; release builds, steady-window medians.
github manually merged commit d5c8861f14 into main 2026-11-29 08:21:46 +00:00
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!1133
No description provided.