A thread remembers what its asks for a buffer's host copy found: 245,000 lookups a frame off the tables' lock, 117 -> 104 ms #1237

Open
github-bot wants to merge 1 commit from github-bot/gh-1237 into main AGit
Owner

@⁠KyleS98 on GitHub · 2026-11-26 01:26 UTC · original
KyleS98:perf/lookup-cache → main · +98 −0 · 2 files · 1 commits · open

What

Every bind of a draw asks for the host copy of each buffer it reads (shadow::find / find_any → lookup). Each ask:

  • takes the one lock of the buffer table,
  • walks back over up to 64 buffers that start below the address,
  • and, for memory outside buffer objects, then takes the windows' lock too.

The built-in profiler (VICTORY_PROFILE=1, sampled in the world only) shows what that costs in the prologue cell:

  • about 245,000 such asks a frame from the title's six recording threads (305,000 with the Series X profile);
  • shadow::lookup at 54 ms of their time together per frame, under draw::readable, which is the second-largest part of State::bind (185 ms a frame over the six threads).

They ask for the same ranges again and again. With this PR a thread remembers what each ask (address, length, kind) found:

  • in a thread-local map, so a remembered ask takes no lock and walks no tree;
  • weakly, so a window nothing else holds can still be let go (let_go_idle looks at the strong count, as before);
  • only for as long as the tables are unchanged: one counter is bumped when a buffer is registered or released, a copy is taken out of a table, or a window is made, and a thread clears its map when the count has moved;
  • for a window it does what loose does when it hands one out: stamps used, widens asked, and counts unsized asks.

VICTORY_LOOKUP_CACHE=0 sends every ask to the tables, as before. A line on the frame-rate log counts both kinds.

Measured

RTX 3090 Ti, warm cache and pipeline library, prologue cell. Each row is the same binary with the switch off and on, using the README's run-253 switch set plus VICTORY_CARD_BUFFERS_MIN_KB=64 VICTORY_CARD_BUFFERS_MB=1280.

tree asks answered by the thread / by the tables frame (mean of the last 12 frame-rate lines) usual frame (frame log)
Series X profile: a183ea2 + this PR only 274,805 / 30,407 117.2 → 104.2 ms 115–151 → 98–101 ms
Series S profile: 9c184b3 + #798 + #1081 + #1171 + #1227 + this 222,000–227,000 / 22,000 84.6 → 72.5 and 72.9 ms (two runs on) 79–80 → 63–72 ms

Each "off" figure is one run. On the Series S tree the build before this change measured 77.2 ms in the same spot, so read the gain there as somewhere between 5 and 12 ms.

Picture: the cell is the same with and without, compared from grabs.

What is left in State::bind

By the same profile, the largest part is HostHeap::mirror and what it calls (buffer_copy, make), with 22 ms a frame of the recording threads waiting for its lock. I haven't touched that here.

AI-assisted (Claude Code, Claude Fable 5.2); runs and grabs on my machine; no game data.

**@⁠KyleS98** on GitHub · 2026-11-26 01:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/1237) `KyleS98:perf/lookup-cache` → `main` · +98 −0 · 2 files · 1 commits · open ## What Every bind of a draw asks for the host copy of each buffer it reads (`shadow::find` / `find_any` → `lookup`). Each ask: - takes the one lock of the buffer table, - walks back over up to 64 buffers that start below the address, - and, for memory outside buffer objects, then takes the windows' lock too. The built-in profiler (`VICTORY_PROFILE=1`, sampled in the world only) shows what that costs in the prologue cell: - about **245,000 such asks a frame** from the title's six recording threads (305,000 with the Series X profile); - `shadow::lookup` at 54 ms of their time together per frame, under `draw::readable`, which is the second-largest part of `State::bind` (185 ms a frame over the six threads). They ask for the same ranges again and again. With this PR a thread remembers what each ask (address, length, kind) found: - in a thread-local map, so a remembered ask takes no lock and walks no tree; - weakly, so a window nothing else holds can still be let go (`let_go_idle` looks at the strong count, as before); - only for as long as the tables are unchanged: one counter is bumped when a buffer is registered or released, a copy is taken out of a table, or a window is made, and a thread clears its map when the count has moved; - for a window it does what `loose` does when it hands one out: stamps `used`, widens `asked`, and counts unsized asks. `VICTORY_LOOKUP_CACHE=0` sends every ask to the tables, as before. A line on the frame-rate log counts both kinds. ## Measured RTX 3090 Ti, warm cache and pipeline library, prologue cell. Each row is the same binary with the switch off and on, using the README's run-253 switch set plus `VICTORY_CARD_BUFFERS_MIN_KB=64 VICTORY_CARD_BUFFERS_MB=1280`. | tree | asks answered by the thread / by the tables | frame (mean of the last 12 frame-rate lines) | usual frame (frame log) | |---|---|---|---| | Series X profile: `a183ea2` + this PR only | 274,805 / 30,407 | 117.2 → **104.2 ms** | 115–151 → **98–101 ms** | | Series S profile: `9c184b3` + #798 + #1081 + #1171 + #1227 + this | 222,000–227,000 / 22,000 | 84.6 → **72.5 and 72.9 ms** (two runs on) | 79–80 → **63–72 ms** | Each "off" figure is one run. On the Series S tree the build before this change measured 77.2 ms in the same spot, so read the gain there as somewhere between 5 and 12 ms. Picture: the cell is the same with and without, compared from grabs. ## What is left in `State::bind` By the same profile, the largest part is `HostHeap::mirror` and what it calls (`buffer_copy`, `make`), with 22 ms a frame of the recording threads waiting for its lock. I haven't touched that here. AI-assisted (Claude Code, Claude Fable 5.2); runs and grabs on my machine; no game data.
Every bind of a draw asks for the host copy of each buffer it reads: under
the tables' one lock, among the 64 buffers that start below the address,
then for memory outside buffers under the windows' lock. In the prologue
cell that is about 245,000 asks a frame from the title's six recording
threads, 54 ms of their time together (VICTORY_PROFILE). A thread now
keeps what each ask (address, length, kind) found, weakly, for as long as
the tables have not changed: 91 % of the asks are answered there.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:00:08 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-26 01:41 UTC · original

I found two stale-cache cases while testing this branch. A recording thread could cache the old buffer under the new generation while registration was waiting for the lock. A loose window could also still be handed out after the idle sweep had removed it. Both regressions fail on cdf74b5 and pass with the fixes on my RX 7900 XT. Fix and focused tests against your branch

**@⁠UwUCammie** on GitHub · 2026-11-26 01:41 UTC · [original](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7180031917) I found two stale-cache cases while testing this branch. A recording thread could cache the old buffer under the new generation while registration was waiting for the lock. A loose window could also still be handed out after the idle sweep had removed it. Both regressions fail on cdf74b5 and pass with the fixes on my RX 7900 XT. [Fix and focused tests against your branch](https://github.com/KyleS98/victory-fork/pull/5)
Author
Owner

@⁠SkillIssueXO on GitHub · 2026-11-26 02:36 UTC · original

AI-assisted local A/B on RTX 5070 Ti, Windows, Series X profile. Same warm-cache build from upstream 53c743d7, stationary Gone Fishing boat view, VICTORY_LOOKUP_CACHE=alt. I counted accepted presents in the interior 17 seconds of four consecutive 20-second epochs.

Mode FPS Median ms p95 ms
Off 6.77 148.5 167.3
On 6.57 152.2 169.4
Off 6.50 153.8 170.7
On 6.54 153.2 174.4

In sampled on-mode timing lines, around 205k–233k buffer lookups per frame came from the thread-local cache. Frame time was similar in this boat view with the cache off or on. This measures one stationary scene on this PC.

**@⁠SkillIssueXO** on GitHub · 2026-11-26 02:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7180952646) AI-assisted local A/B on RTX 5070 Ti, Windows, Series X profile. Same warm-cache build from upstream `53c743d7`, stationary Gone Fishing boat view, `VICTORY_LOOKUP_CACHE=alt`. I counted accepted presents in the interior 17 seconds of four consecutive 20-second epochs. | Mode | FPS | Median ms | p95 ms | | --- | ---: | ---: | ---: | | Off | 6.77 | 148.5 | 167.3 | | On | 6.57 | 152.2 | 169.4 | | Off | 6.50 | 153.8 | 170.7 | | On | 6.54 | 153.2 | 174.4 | In sampled on-mode timing lines, around 205k–233k buffer lookups per frame came from the thread-local cache. Frame time was similar in this boat view with the cache off or on. This measures one stationary scene on this PC.
Author
Owner

@⁠KyleS98 on GitHub · 2026-11-26 06:42 UTC · original

@⁠UwUCammie both cases are real, thank you. The first one is plainly my mistake: register counted the table change before its insert, so a thread that asked in between kept the old answer under the new count. The maintainer has since carried the cache into main as 32be36d (off by default there, VICTORY_LOOKUP_CACHE=1|alt) and your ordering fix by hand as bc6ee68, from #1245. So main now has the corrected form and this branch (cdf74b5) should not be used as it stands.

@⁠SkillIssueXO thanks for the paired run. No gain in a stationary view at 150 ms a frame is consistent with what I measured: the saving is lock time on the title's recording threads, and it shows where they are the limit. In the prologue cell on a 3090 Ti that was 54 ms of thread time a frame over six threads (117 -> 104 ms on Series X, 84.6 -> 72.5 ms on Series S, switch off and on, same binary); the maintainer's run 293 puts it at about 14 ms a frame. Where the frame waits on something else, as in your boat view, it gives nothing. I am not claiming a general frame-rate gain beyond those scenes.

Since main has this with the fix, this PR is superseded and can be closed.

AI-assisted (Claude Code, Claude Fable 5.2).

**@⁠KyleS98** on GitHub · 2026-11-26 06:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7184700290) @⁠UwUCammie both cases are real, thank you. The first one is plainly my mistake: `register` counted the table change before its insert, so a thread that asked in between kept the old answer under the new count. The maintainer has since carried the cache into `main` as `32be36d` (off by default there, `VICTORY_LOOKUP_CACHE=1|alt`) and your ordering fix by hand as `bc6ee68`, from #1245. So `main` now has the corrected form and this branch (`cdf74b5`) should not be used as it stands. @⁠SkillIssueXO thanks for the paired run. No gain in a stationary view at 150 ms a frame is consistent with what I measured: the saving is lock time on the title's recording threads, and it shows where they are the limit. In the prologue cell on a 3090 Ti that was 54 ms of thread time a frame over six threads (117 -> 104 ms on Series X, 84.6 -> 72.5 ms on Series S, switch off and on, same binary); the maintainer's run 293 puts it at about 14 ms a frame. Where the frame waits on something else, as in your boat view, it gives nothing. I am not claiming a general frame-rate gain beyond those scenes. Since `main` has this with the fix, this PR is superseded and can be closed. AI-assisted (Claude Code, Claude Fable 5.2).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1237/head:github-bot/gh-1237'
git switch 'github-bot/gh-1237'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1237'
git switch 'github-bot/gh-1237'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1237'
git switch 'github-bot/gh-1237'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1237'
git switch 'main'
git merge --squash 'github-bot/gh-1237'
git switch 'main'
git merge --ff-only 'github-bot/gh-1237'
git switch 'main'
git merge 'github-bot/gh-1237'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.