perf(gpu): skip redundant held-slot touch and batch record stats #509

Manually merged
github merged 1 commit from github-bot/gh-509 into main 2026-12-05 17:30:19 +00:00 AGit
Owner

@⁠Not4Eric on GitHub · 2026-12-04 20:24 UTC · original
Not4Eric:perf/records-skip-touch-batch-stats → main · +29 −12 · 2 files · 1 commits · merged 2026-12-05 17:29 UTC

What this does

Two hot-path reductions in view-record bookkeeping:

  1. Skips c.touch(slot) when a slot is already held/ready in records::told_at (same slot as cell.load) and defers c.touch(slot) in draw::State::scan past the self.ready cache hit path (avoiding redundant c.touch(slot) calls — each a relaxed atomic load plus conditional store — on the vast majority of descriptors).
  2. Batches STATS[MOVED] and STATS[STOOD] increments per each_view chunk in records::round instead of calling global AtomicU64::fetch_add on every cell that changed.

Checks

  • N/A: pure performance optimization preserving the same reclaim decisions and stats counts.
  • N/A: no switches added, changed, or removed.
  • No unrelated cleanup: diff is limited to told/told_at/round in crates/victory-gpu/src/records.rs and moving c.touch(slot) in crates/victory-gpu/src/draw.rs.
  • N/A: no unit tests exist under records:: in victory-gpu (0 matched); behavioural invariance verified by combined gameplay testing.
  • Checked open PR queue: independent of #445 and of perf/draw-split-uav-scan-cache.
  • cargo xtask policy passed (360 files ok); no fork-only files, configs, or build outputs.

Verified

  • cargo xtask policy — 360 files ok
  • PKG=victory-gpu ./build.sh test --lib -- records:: --test-threads=1 — compiled cleanly with 0 warnings (0 tests matched under records::)
  • Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton) where records::round processes ~260k–310k title slots/frame; not benchmarked in isolation.

Cost

None (reduces atomic contention in records::round and draw::State::scan; 0 new warnings).

AI-assisted: yes

**@⁠Not4Eric** on GitHub · 2026-12-04 20:24 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/509) `Not4Eric:perf/records-skip-touch-batch-stats` → `main` · +29 −12 · 2 files · 1 commits · merged 2026-12-05 17:29 UTC ## What this does Two hot-path reductions in view-record bookkeeping: 1. Skips `c.touch(slot)` when a slot is already held/ready in `records::told_at` (same slot as `cell.load`) and defers `c.touch(slot)` in `draw::State::scan` past the `self.ready` cache hit path (avoiding redundant `c.touch(slot)` calls — each a relaxed atomic load plus conditional store — on the vast majority of descriptors). 2. Batches `STATS[MOVED]` and `STATS[STOOD]` increments per `each_view` chunk in `records::round` instead of calling global `AtomicU64::fetch_add` on every cell that changed. ## Checks - N/A: pure performance optimization preserving the same reclaim decisions and stats counts. - N/A: no switches added, changed, or removed. - [x] No unrelated cleanup: diff is limited to `told`/`told_at`/`round` in `crates/victory-gpu/src/records.rs` and moving `c.touch(slot)` in `crates/victory-gpu/src/draw.rs`. - N/A: no unit tests exist under `records::` in `victory-gpu` (`0` matched); behavioural invariance verified by combined gameplay testing. - [x] Checked open PR queue: independent of #445 and of `perf/draw-split-uav-scan-cache`. - [x] `cargo xtask policy` passed (`360 files ok`); no fork-only files, configs, or build outputs. ## Verified - `cargo xtask policy` — `360 files ok` - `PKG=victory-gpu ./build.sh test --lib -- records:: --test-threads=1` — compiled cleanly with 0 warnings (`0` tests matched under `records::`) - Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton) where `records::round` processes ~260k–310k title slots/frame; not benchmarked in isolation. ## Cost None (reduces atomic contention in `records::round` and `draw::State::scan`; 0 new warnings). AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 20:27:32 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 22:15 UTC · original

Checked 94e4148 on native Windows (one NVIDIA desktop card, didn't run the game).

victory-gpu lib tests: 352 passed, 5 failed on the PR and 353 passed, 4 failed on main. The four are the ones that already fail natively here (two indirect host_list tests, two pipeline::host library loads), the fifth is the flaky watch test, which passed 2 of 3 reruns on the PR. Clippy with and without diagnostics shows nothing new in records.rs or draw.rs, only the two old draw.rs warnings main has too. It merges cleanly with current main and with #510 (both touch State::scan), and after merging both, the one c.touch in scan still sits after the ready cache-hit continue.

On "identical slot lifetime" I traced who reads what touch writes. Canon::touch (records.rs:506) only stores STEP into Canon.named[slot], and the only reader of that is the aged check in reclaim (records.rs:600). reclaim skips any slot with refs != 0 before it looks at age (records.rs:608).

The told_at skip (records.rs:816-818) is safe. When resolve gives the same slot the cell already names, that cell took a hold on it before the swap (records.rs:820-825), so refs is at least 1 and reclaim never ages it. When the cell later lets go, release (records.rs:588-593) stamps named again, so ageing starts from the release on both sides.

The scan move (draw.rs:2822 to 2844) isn't strictly identical, but I don't think it changes anything in practice. A repeated SRV hit on the same record in the same list epoch no longer restamps the slot, only the first miss does. Main already does the same thing one level up: the scanned hit (draw.rs:2766-2770) returns for the whole table before any touch. And ready is cleared with scanned in tables_done (draw.rs:609-610). For a slot to age out it would need refs == 0 for at least rest = 2*sweep+2 required rounds (records.rs:889). Descriptor writes into title heaps tell the cell straight away (descriptor.rs:162-164) or, for port heaps, on the next round, and the audit covers every heap in about sweep rounds. So any slot a draw can reach gets held long before it could rest. If one did get rested anyway, quick_key goes to 0, so the next scan sees fresh, misses the cache and re-mirrors (draw.rs:2823-2830). I'd soften the wording to "same reclaim decisions" rather than identical.

The stats batching looks right. MOVED is still counted once per swap and STOOD under the same condition. told() flushes inline (records.rs:795-803) and each each_view chunk flushes at the end of its closure with no early exit (records.rs:868-885). The only reader is line(), which swaps the counters to zero once per report (records.rs:957-960), so at worst a few counts land in the next report. One nit on the description: main never did a fetch_add per slot in round, only for cells that actually changed (the early returns skip it), so the contention saved is per moved cell, which should be far fewer than the cells told each frame. Same for touch, which is a relaxed load plus a store only when the step changed, not an atomic RMW.

Small thing: cargo fmt wants the new stood expression at records.rs:832-834 split over several lines, it's 101 columns with max_width 100. I didn't try a throwaway test for the ageing part since Canon::new needs a live host heap and records() set up, so the lifetime argument above is from reading the code only.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 22:15 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/509#issuecomment-7425717884) Checked 94e4148 on native Windows (one NVIDIA desktop card, didn't run the game). victory-gpu lib tests: 352 passed, 5 failed on the PR and 353 passed, 4 failed on main. The four are the ones that already fail natively here (two indirect host_list tests, two pipeline::host library loads), the fifth is the flaky watch test, which passed 2 of 3 reruns on the PR. Clippy with and without diagnostics shows nothing new in records.rs or draw.rs, only the two old draw.rs warnings main has too. It merges cleanly with current main and with #510 (both touch State::scan), and after merging both, the one c.touch in scan still sits after the ready cache-hit continue. On "identical slot lifetime" I traced who reads what touch writes. Canon::touch (records.rs:506) only stores STEP into Canon.named[slot], and the only reader of that is the aged check in reclaim (records.rs:600). reclaim skips any slot with refs != 0 before it looks at age (records.rs:608). The told_at skip (records.rs:816-818) is safe. When resolve gives the same slot the cell already names, that cell took a hold on it before the swap (records.rs:820-825), so refs is at least 1 and reclaim never ages it. When the cell later lets go, release (records.rs:588-593) stamps named again, so ageing starts from the release on both sides. The scan move (draw.rs:2822 to 2844) isn't strictly identical, but I don't think it changes anything in practice. A repeated SRV hit on the same record in the same list epoch no longer restamps the slot, only the first miss does. Main already does the same thing one level up: the scanned hit (draw.rs:2766-2770) returns for the whole table before any touch. And ready is cleared with scanned in tables_done (draw.rs:609-610). For a slot to age out it would need refs == 0 for at least rest = 2*sweep+2 required rounds (records.rs:889). Descriptor writes into title heaps tell the cell straight away (descriptor.rs:162-164) or, for port heaps, on the next round, and the audit covers every heap in about sweep rounds. So any slot a draw can reach gets held long before it could rest. If one did get rested anyway, quick_key goes to 0, so the next scan sees fresh, misses the cache and re-mirrors (draw.rs:2823-2830). I'd soften the wording to "same reclaim decisions" rather than identical. The stats batching looks right. MOVED is still counted once per swap and STOOD under the same condition. told() flushes inline (records.rs:795-803) and each each_view chunk flushes at the end of its closure with no early exit (records.rs:868-885). The only reader is line(), which swaps the counters to zero once per report (records.rs:957-960), so at worst a few counts land in the next report. One nit on the description: main never did a fetch_add per slot in round, only for cells that actually changed (the early returns skip it), so the contention saved is per moved cell, which should be far fewer than the cells told each frame. Same for touch, which is a relaxed load plus a store only when the step changed, not an atomic RMW. Small thing: cargo fmt wants the new stood expression at records.rs:832-834 split over several lines, it's 101 columns with max_width 100. I didn't try a throwaway test for the ageing part since Canon::new needs a live host heap and records() set up, so the lifetime argument above is from reading the code only. AI-assisted: yes
github-bot force-pushed github-bot/gh-509 from 94e41481d4 to 8e3a119fbe 2026-12-05 00:05:41 +00:00 Compare
Author
Owner

@⁠Not4Eric on GitHub · 2026-12-05 00:00 UTC · original

Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this

Pushed updates addressing your review:

  • Wrapped let stood = u64::from(...) in records.rs to stay within 100 columns.
  • Updated the PR description wording from "identical slot lifetime" to "same reclaim decisions" and clarified that round batches STATS per moved cell.
**@⁠Not4Eric** on GitHub · 2026-12-05 00:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/509#issuecomment-7427749204) Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this Pushed updates addressing your review: - Wrapped `let stood = u64::from(...)` in `records.rs` to stay within 100 columns. - Updated the PR description wording from "identical slot lifetime" to "same reclaim decisions" and clarified that `round` batches `STATS` per moved cell.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 00:59 UTC · original

Re-checked 8e3a119 on native Windows (didn't run the game).

The stood expression at records.rs:832-838 is fmt-clean now, and the description says "same reclaim decisions". The full lib run shows only the four failures main already has natively, clippy has nothing new (only the two old draw.rs warnings), and it still merges cleanly onto current main.

A tiny wording leftover, not blocking. Point 2 still says main did a fetch_add "unconditionally on every slot", but main only did it for cells that changed, and point 1 calls the touches atomic when touch is a relaxed load plus a store only when the step changed.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 00:59 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/509#issuecomment-7428826125) Re-checked 8e3a119 on native Windows (didn't run the game). The stood expression at records.rs:832-838 is fmt-clean now, and the description says "same reclaim decisions". The full lib run shows only the four failures main already has natively, clippy has nothing new (only the two old draw.rs warnings), and it still merges cleanly onto current main. A tiny wording leftover, not blocking. Point 2 still says main did a fetch_add "unconditionally on every slot", but main only did it for cells that changed, and point 1 calls the touches atomic when touch is a relaxed load plus a store only when the step changed. AI-assisted: yes
github manually merged commit 86b141bfe3 into main 2026-12-05 17:30:19 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.