perf(gpu): batch nothing_new refresh checks under one JournalRead lock and single-lock watch::writes #1373

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

@⁠qlfu on GitHub · 2026-11-28 18:17 UTC · original
qlfu:pr/journal-batch-nothing-new-perf → main · +259 −31 · 3 files · 1 commits · closed without merging

Summary

Reduces global JOURNAL RwLock contention and atomic counter cache-line bouncing during per-submission buffer refresh checks (Batch::refresh_front, Batch::refresh_ahead, Batch::flush_all), where ~82–84% (~5,100 of ~6,100 copies/frame) are skipped via nothing_new:

  1. Lock-free-nesting batched nothing_new filtering (watch.rs, shadow.rs, host.rs):
    • Adds watch::JournalRead + JournalRead::nothing_new_min() with a single-page BTreeMap::get fast path (avoiding range() iterator setup for single-page ranges).
    • Adds Shadow::nothing_new_snap() and shadow::filter_nothing_new_chunk() (stack-allocated [CopySnap; 32], zero heap allocations): snapshots each shadow's copied/ranged lower bound first and releases all Shadow locks before acquiring a single shared JOURNAL.read() lock for up to 32 spans (eliminating any JOURNAL <-> Shadow::copied lock-order inversion), falling back to exact Shadow::nothing_new only for rare multi-page non-uniform spans that fail the conservative check.
    • Uses retain_changed() for small flushes (<= 256) and 32-span chunking inside wide_each for large flushes (> 256), cutting JOURNAL.read() acquisitions and FLUSHES[2] atomic RMWs by ~32x across worker threads.
  2. Single JOURNAL.read() fast path in watch::writes():
    • Combines the ahead lookup and guarded && published(start, end) check under a single journal() read guard instead of locking JOURNAL twice on guarded view-memory refreshes.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored (including new test watch::journal_read_tests::nothing_new_min_matches_single_and_multi_page_writes).
  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked (default and --all-features): 0 warnings in modified lines.
  • cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory: exit 0.

Clean Idle-PC A/B Benchmark (Ryzen 7 5700X + RTX 4070 Ti 12 GB, 1440p Series X, DLSS Quality, -FrameGen, 90s steady gameplay)

Metric main (9ce3cf9, BASE_9ce3cf9_fg_clean) This PR (PR8_journal_fg_clean) Delta
Submitting thread total (sub_all) mean / max 52.45 / 75.10 ms 50.16 / 67.50 ms -2.29 ms (-4.4%) / -7.60 ms
in the lists' steps median / mean 19.50 / 20.13 ms 18.80 / 19.50 ms -3.6% / -3.1%
refreshes per 1k copies median / mean 2.05 / 2.11 ms 1.98 / 2.06 ms -3.4% / -2.4%
Mean FPS / min / max 18.54 (13.3 / 25.8) 19.17 (14.0 / 30.6) +3.4%
p10 / p90 FPS 14.3 / 25.3 14.6 / 26.7 +2.1% / +5.5%
GPU busy / copy-back 71.0% / 16.7 ms 73.0% / 14.85 ms +2 pp / -11.1%
WARNs / ERRORs 0 / 0 0 / 0 clean
**@⁠qlfu** on GitHub · 2026-11-28 18:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1373) `qlfu:pr/journal-batch-nothing-new-perf` → `main` · +259 −31 · 3 files · 1 commits · closed without merging ### Summary Reduces global `JOURNAL` `RwLock` contention and atomic counter cache-line bouncing during per-submission buffer refresh checks (`Batch::refresh_front`, `Batch::refresh_ahead`, `Batch::flush_all`), where ~82–84% (~5,100 of ~6,100 copies/frame) are skipped via `nothing_new`: 1. **Lock-free-nesting batched `nothing_new` filtering (`watch.rs`, `shadow.rs`, `host.rs`):** - Adds `watch::JournalRead` + `JournalRead::nothing_new_min()` with a single-page `BTreeMap::get` fast path (avoiding `range()` iterator setup for single-page ranges). - Adds `Shadow::nothing_new_snap()` and `shadow::filter_nothing_new_chunk()` (stack-allocated `[CopySnap; 32]`, zero heap allocations): snapshots each shadow's `copied`/`ranged` lower bound first and releases all `Shadow` locks **before** acquiring a single shared `JOURNAL.read()` lock for up to 32 spans (eliminating any `JOURNAL <-> Shadow::copied` lock-order inversion), falling back to exact `Shadow::nothing_new` only for rare multi-page non-uniform spans that fail the conservative check. - Uses `retain_changed()` for small flushes (`<= 256`) and 32-span chunking inside `wide_each` for large flushes (`> 256`), cutting `JOURNAL.read()` acquisitions and `FLUSHES[2]` atomic RMWs by ~32x across worker threads. 2. **Single `JOURNAL.read()` fast path in `watch::writes()`:** - Combines the `ahead` lookup and `guarded && published(start, end)` check under a single `journal()` read guard instead of locking `JOURNAL` twice on guarded view-memory refreshes. ### Verification - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **455 passed, 0 failed, 36 ignored** (including new test `watch::journal_read_tests::nothing_new_min_matches_single_and_multi_page_writes`). - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked` (default and `--all-features`): **0 warnings in modified lines**. - `cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory`: exit `0`. ### Clean Idle-PC A/B Benchmark (Ryzen 7 5700X + RTX 4070 Ti 12 GB, 1440p Series X, DLSS Quality, `-FrameGen`, 90s steady gameplay) | Metric | `main` (`9ce3cf9`, `BASE_9ce3cf9_fg_clean`) | This PR (`PR8_journal_fg_clean`) | Delta | |---|---:|---:|---:| | Submitting thread total (`sub_all`) mean / max | `52.45 / 75.10 ms` | **`50.16 / 67.50 ms`** | **-2.29 ms (-4.4%) / -7.60 ms** | | `in the lists' steps` median / mean | `19.50 / 20.13 ms` | **`18.80 / 19.50 ms`** | **-3.6% / -3.1%** | | `refreshes` per 1k copies median / mean | `2.05 / 2.11 ms` | **`1.98 / 2.06 ms`** | **-3.4% / -2.4%** | | Mean FPS / min / max | `18.54` (`13.3` / `25.8`) | **`19.17`** (`14.0` / **`30.6`**) | **+3.4%** | | p10 / p90 FPS | `14.3` / `25.3` | **`14.6`** / **`26.7`** | +2.1% / +5.5% | | GPU busy / `copy-back` | `71.0%` / `16.7 ms` | **`73.0%`** / **`14.85 ms`** | +2 pp / -11.1% | | WARNs / ERRORs | `0 / 0` | **`0 / 0`** | clean |
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 18:18:35 +00:00
github-bot closed this pull request 2026-11-28 20:39:51 +00:00
Author
Owner

@⁠qlfu on GitHub · 2026-11-28 20:39 UTC · original

Closing after bisecting on current main: batching \ ilter_nothing_new_chunk\ inside parallel \wide_each_from\ refreshes serializes adjacent dirty \Self::update\ spans and regresses
efreshes\ vs 1-by-1 work stealing, and \3055afd\ already removed the global \hold_all\ contention in \watch.rs.

**@⁠qlfu** on GitHub · 2026-11-28 20:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1373#issuecomment-7245441315) Closing after bisecting on current main: batching \ ilter_nothing_new_chunk\ inside parallel \wide_each_from\ refreshes serializes adjacent dirty \Self::update\ spans and regresses \ efreshes\ vs 1-by-1 work stealing, and \3055afd\ already removed the global \hold_all\ contention in \watch.rs\.

Pull request closed

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!1373
No description provided.