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 #1234

Open
KyleS98 wants to merge 1 commit from upstream-pr/1237 into main
KyleS98 commented 2026-11-26 01:26:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T01:26:10Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6617389066 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1237). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T01:26:10Z. --- ## 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.
UwUCammie commented 2026-11-26 02:08:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-26T01:41:42Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7180031917 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7180031917). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-26T01:41:42Z. --- 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)
SkillIssueXO commented 2026-11-26 03:06:50 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by SkillIssueXO on 2026-11-26T02:36:07Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7180952646 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7180952646). Originally posted by [SkillIssueXO](https://github.com/SkillIssueXO) on 2026-11-26T02:36:07Z. --- 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.
KyleS98 commented 2026-11-26 07:03:54 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T06:42:24Z.


@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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7184700290 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7184700290). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-26T06:42:24Z. --- @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).
Filip722 commented 2026-11-27 09:26:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-27T09:26:52Z.


On Bazzite with an RTX 5060 Laptop 8 GB, NVIDIA 615.78.08 and GE-Proton11-14 / vkd3d-proton 3.2.0, I tested the lookup-cache implementation carried in the 4c60466 line. My local integration was 090eef7 with the same 174 MiB constants import active throughout. Series S, 50% internal render scale, one warm process and a fixed opening-room view.

VICTORY_LOOKUP_CACHE=alt alternated in 20-second phases. I counted successful Present tokens in three complete 18-second windows per state, trimming one second at each boundary.

Off On
Median of three phase rates 6.26 FPS 6.33 FPS
Median of the phase p95 frame intervals 218 ms 174 ms
Typical render-thread CPU 101 ms/frame 98 ms/frame

The enabled phases served about 223k lookups/frame from the thread-local cache and 19k from the tables. Draw counts were about 4,400/frame in both states. Minimum free VRAM across the measured phases was 1,469 MiB. The camera responded to input after measurement. This is evidence for shorter frame-time tails in one scene on Proton. It leaves longer-session remaps and overall gameplay FPS open.

Assisted by Codex (GPT-6.2-Sol High).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7214691948 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1237#issuecomment-7214691948). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-27T09:26:52Z. --- On Bazzite with an RTX 5060 Laptop 8 GB, NVIDIA 615.78.08 and GE-Proton11-14 / vkd3d-proton 3.2.0, I tested the lookup-cache implementation carried in the `4c60466` line. My local integration was `090eef7` with the same 174 MiB constants import active throughout. Series S, 50% internal render scale, one warm process and a fixed opening-room view. `VICTORY_LOOKUP_CACHE=alt` alternated in 20-second phases. I counted successful Present tokens in three complete 18-second windows per state, trimming one second at each boundary. | | Off | On | |---|---:|---:| | Median of three phase rates | 6.26 FPS | 6.33 FPS | | Median of the phase p95 frame intervals | 218 ms | 174 ms | | Typical render-thread CPU | 101 ms/frame | 98 ms/frame | The enabled phases served about 223k lookups/frame from the thread-local cache and 19k from the tables. Draw counts were about 4,400/frame in both states. Minimum free VRAM across the measured phases was 1,469 MiB. The camera responded to input after measurement. This is evidence for shorter frame-time tails in one scene on Proton. It leaves longer-session remaps and overall gameplay FPS open. Assisted by Codex (GPT-6.2-Sol High).
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/1237:upstream-pr/1237'
git switch 'upstream-pr/1237'

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/1237'
git switch 'upstream-pr/1237'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1237'
git switch 'upstream-pr/1237'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1237'
git switch 'main'
git merge --squash 'upstream-pr/1237'
git switch 'main'
git merge --ff-only 'upstream-pr/1237'
git switch 'main'
git merge 'upstream-pr/1237'
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
fxceless/victory-fork!1234
No description provided.