perf(gpu): use pre-snapshotted ahead list in refresh sift paths (~7900 journal lock acquisitions/frame → ~48) #2504

Open
erax4193 wants to merge 17 commits from upstream-pr/2504 into main
erax4193 commented 2026-11-29 13:43:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by erax4193 on 2026-11-29T13:43:55Z.


Problem

In flush_all and refresh_front, the light-refresh "few" path (len ≤ 256)
already calls watch::ahead_snapshot_into(&mut self.ahead_snap) before the
retain loop — but then immediately calls shadow.nothing_new(from, len) per
resource, which acquires journal() internally, ignoring the snapshot just
captured.

From the logs on a Core Ultra 9 275HX + RTX 5070L running the game's prologue:

refreshes 28.6 ms in 48 flushes of 7917, 6943 of them known to copy nothing

7917 resources × 48 flushes/frame ≈ 7920 journal() lock acquisitions per
frame, all on the submission thread, to answer "nothing changed" for 87.7% of
them. The lock is uncontested but not free: each acquisition reads an RWLock,
branches on the ahead list, and touches the per-page epoch array.

Fix

Two-line change per site: pass &self.ahead_snap to nothing_new_with —
the lock-free version that uses the pre-snapshotted ahead list — instead of
calling nothing_new which re-acquires the journal.

flush_all (line ~12680): snapshot is already taken at the top of the
branch; just pass it to retain.

refresh_front (line ~12498): no snapshot taken before the sift; add
one ahead_snapshot_into call, then use nothing_new_with in retain.

Result: ~48 snapshot acquisitions/frame instead of ~7920 per-resource ones.

Expected impact

The 28.6 ms/frame refresh time comes almost entirely from the per-resource
journal lock overhead — the 974 resources that actually copy data take far
less time. With the lock removed from the sift loop, the refresh cost should
drop close to the actual copy time of those ~12% dirty resources.

Notes

  • nothing_new_with is semantically equivalent when the snapshot is fresh:
    the snapshot is taken on the same thread, immediately before the loop, with
    no yield points between.
  • The existing batch path (uses nothing_new_all) is unchanged — it
    already batches the journal read.
  • The many / flush_sift path (> 256 resources per flush) is unchanged;
    that path uses wide_each which already distributes the per-resource cost.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5551302328 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504). Originally posted by [erax4193](https://github.com/erax4193) on 2026-11-29T13:43:55Z. --- ## Problem In `flush_all` and `refresh_front`, the light-refresh "few" path (`len ≤ 256`) already calls `watch::ahead_snapshot_into(&mut self.ahead_snap)` before the retain loop — but then immediately calls `shadow.nothing_new(from, len)` per resource, which acquires `journal()` internally, ignoring the snapshot just captured. From the logs on a Core Ultra 9 275HX + RTX 5070L running the game's prologue: ``` refreshes 28.6 ms in 48 flushes of 7917, 6943 of them known to copy nothing ``` 7917 resources × 48 flushes/frame ≈ 7920 `journal()` lock acquisitions per frame, all on the submission thread, to answer "nothing changed" for 87.7% of them. The lock is uncontested but not free: each acquisition reads an RWLock, branches on the ahead list, and touches the per-page epoch array. ## Fix Two-line change per site: pass `&self.ahead_snap` to `nothing_new_with` — the lock-free version that uses the pre-snapshotted ahead list — instead of calling `nothing_new` which re-acquires the journal. **`flush_all`** (line ~12680): snapshot is already taken at the top of the branch; just pass it to `retain`. **`refresh_front`** (line ~12498): no snapshot taken before the sift; add one `ahead_snapshot_into` call, then use `nothing_new_with` in `retain`. Result: ~48 snapshot acquisitions/frame instead of ~7920 per-resource ones. ## Expected impact The 28.6 ms/frame refresh time comes almost entirely from the per-resource journal lock overhead — the 974 resources that actually copy data take far less time. With the lock removed from the sift loop, the refresh cost should drop close to the actual copy time of those ~12% dirty resources. ## Notes - `nothing_new_with` is semantically equivalent when the snapshot is fresh: the snapshot is taken on the same thread, immediately before the loop, with no yield points between. - The existing `batch` path (uses `nothing_new_all`) is unchanged — it already batches the journal read. - The `many` / `flush_sift` path (> 256 resources per flush) is unchanged; that path uses `wide_each` which already distributes the per-resource cost. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xmorvay commented 2026-11-30 14:06:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xmorvay on 2026-11-30T14:06:07Z.


tested the two refresh sift changes from this pr on a 4070 super with a 7900x3d and 32 gb of ram

three launches from the same post prologue save with the same scripted camera turns
series x at 1440p with dlss quality and frame generation off
both builds used the same input changes and the same persistent cache

run order samples median ms p90 ms
patched 13 51.6 63.4
control 14 62.25 75
patched 14 59.3 72.3

these are window title samples taken every two seconds from second 68 to second 96 with more than 3000 draws per frame
the percentile describes the sampled readings rather than individual frames

all three runs reached the world and finished with zero failed pipelines
both patched runs had lower sampled frame times but the cache loaded more slowly in the control and the draw counts varied
i still saw slow turns on the second patched run so i would treat this as a result worth reproducing rather than a fix for camera stutter

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280835897 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504#issuecomment-7280835897). Originally posted by [xmorvay](https://github.com/xmorvay) on 2026-11-30T14:06:07Z. --- tested the two refresh sift changes from this pr on a 4070 super with a 7900x3d and 32 gb of ram three launches from the same post prologue save with the same scripted camera turns series x at 1440p with dlss quality and frame generation off both builds used the same input changes and the same persistent cache | run order | samples | median ms | p90 ms | | --- | ---: | ---: | ---: | | patched | 13 | 51.6 | 63.4 | | control | 14 | 62.25 | 75 | | patched | 14 | 59.3 | 72.3 | these are window title samples taken every two seconds from second 68 to second 96 with more than 3000 draws per frame the percentile describes the sampled readings rather than individual frames all three runs reached the world and finished with zero failed pipelines both patched runs had lower sampled frame times but the cache loaded more slowly in the control and the draw counts varied i still saw slow turns on the second patched run so i would treat this as a result worth reproducing rather than a fix for camera stutter
paales commented 2026-11-30 20:51:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by paales on 2026-11-30T20:51:59Z.


Written by 🤖:

In-game numbers, tested together with #4340 in one build, so the two are not told apart. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count.

Base: main 84bd61e2 with #3918, #1727, #3553, #3043, #4206 (VICTORY_FILL_AHEAD=1), #4138 and #720 (VICTORY_HEAP_WORKER=1). One run each, back to back:

base with #2504 and #4340
the submitting thread per frame 35.4 ms 42.5 ms
of it, refreshes 12.9 ms 19.4 ms
copies in the card's memory 7.6 ms 9.7 ms
seconds with a frame over 40 ms 40 40
seconds with a frame over 100 ms 11 7

I could not measure a gain. One run is not enough to call it a loss on this PC either.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7291579510 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504#issuecomment-7291579510). Originally posted by [paales](https://github.com/paales) on 2026-11-30T20:51:59Z. --- _Written by 🤖:_ In-game numbers, tested together with #4340 in one build, so the two are not told apart. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count. Base: `main` 84bd61e2 with #3918, #1727, #3553, #3043, #4206 (`VICTORY_FILL_AHEAD=1`), #4138 and #720 (`VICTORY_HEAP_WORKER=1`). One run each, back to back: | | base | with #2504 and #4340 | | --- | --- | --- | | the submitting thread per frame | 35.4 ms | 42.5 ms | | of it, refreshes | 12.9 ms | 19.4 ms | | copies in the card's memory | 7.6 ms | 9.7 ms | | seconds with a frame over 40 ms | 40 | 40 | | seconds with a frame over 100 ms | 11 | 7 | I could not measure a gain. One run is not enough to call it a loss on this PC either.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2504:upstream-pr/2504'
git switch 'upstream-pr/2504'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2504'
git switch 'upstream-pr/2504'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2504'
git switch 'upstream-pr/2504'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2504'
git switch 'main'
git merge --squash 'upstream-pr/2504'
git switch 'main'
git merge --ff-only 'upstream-pr/2504'
git switch 'main'
git merge 'upstream-pr/2504'
git push origin 'main'
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!2504
No description provided.