WIP: perf(vk): the submission walks only the retired pools still holding an import (RX_VK_RETIRED_HELD=0 to disable) #2029

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/vk-retired-held into main
Contributor

Summary

At every part of a submission the give-back of retired imports (retired_imports_give_back) walked the retired
pools, a deque of map nodes that only grows, and every free of the game's asked memory_guest_imported, which walked
every retired pool too. Main already passes over the oldest retired pools given back; the walk of the rest stayed, and
memory_guest_imported still walks them all.

With this, retire_pool lists a retired pool that still has an import, in the order of retirement
(retired_held, linked through the pools themselves: Pool::held_next and a tail pointer, so listing one allocates
nothing), reaching the pool through its node once the table's node is extracted; retired_imports_give_back unlinks it
as it gives the import back (the one place a retired pool loses its import), writing nothing for the pools it keeps. The
give-back and memory_guest_imported walk that list instead. The same imports are given back, with the same budget
figures and answers. Either way, a line after the vk: imports: line counts the retired pools each walk looked at
(parts and calls), and Tracy builds time both walks in zones of their own. The result expected: less CPU time a
submission when many pools have been retired; not measured yet.

The switch: RX_VK_RETIRED_HELD (new, a kill switch, bool, its row in gpu/vk/switches.def), on by default as
docs/dev/standards.md (Switches) asks of a switch's first push; read once; =0 keeps main's walk, in the give-back and
the free's check both.

From 12168bb8 on exp/x86-asm-sync (the half of that commit that rebuilt the GPU-visible ranges in asm is not here).

Read first: retire_pool, retired_imports_give_back and memory_guest_imported in gpu/vk/vk_memory.cpp, then
tests/test_retired_held.py.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head e26cc20c on main 9dd41326. The checks ran at 91960bc2 on main b62932a9, the same commits before a rebase onto 9dd41326, which added only lift files (#1905) that none of these checks reads. Light queue jobs fb-2029-3 and fb-2029-4 of this PC's job queue (the first found compile errors in the new fixtures, fixed before the second), each check in a hidden console through tests/run_all.py --strict --exact --timeout 1200 --jobs 2: tests/test_retired_held.py, tests/test_import_reach.py and tests/test_switch_table.py pass; tests/test_guest_imported.py and tests/test_pending_guest_import.py fail, with the same compile error (import_reach undeclared in their fixtures) on main @ 9dd41326 in the same job. At the test commit cc8c828d tests/test_retired_held.py fails, as expected (retire_pool allocates more with the vector list). The Windows game build's own compile of gpu/vk/vk_memory.cpp (syntax only) passes. Not run this round: every check --changed picks (a heavy batch), the Linux-target compile (the local tool could not read its build profile), tests/test_vbytes.py (hangs on this PC).

It has NOT run in the game on this PC yet.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest into Hyrule Field and back, then a long session (30 minutes or
    more, pools retire as scenes load) and a heavy view (Hyrule Field at dusk, the camera turned), on main @ 9dd41326, this branch with RX_VK_RETIRED_HELD=0 and this branch unset (on), each warmed a minute, interleaved (ABC ABC ABC), expecting
    the same picture, no FATAL or device lost, the vk: imports: lines alike, fewer pools looked at in the vk: retired walks line unset than with =0, and average fps, 1% lows, median and p99 frame times and peak RAM and VRAM of this branch unset at least those of the other two; a difference beyond the runs' spread is a gain or a loss, one within it is no
    difference measured (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest into Hyrule Field and back five minutes and a
    long session, main, this branch with RX_VK_RETIRED_HELD=0 and unset, warmed and interleaved, expecting the same
    picture and no FATAL or device lost (the test farm: linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck:
    Kokiri Forest to Hyrule Field and back five minutes, main @ 9dd41326, this branch with RX_VK_RETIRED_HELD=0 and unset, warmed up, interleaved, the log, frame times and a screenshot)
  • Linux: build the renderer and run python3 -I -B tests/test_retired_held.py, expecting PASS (by hand)
  • A PC with pre-commit and ruff installed: mise run test and mise run lint at this head, expecting every failure to
    fail on main too and lint to pass (by hand; neither tool is installed on this PC)

Measurements

Verdict: not measured in play yet: no micro-benchmark of this port and no run in the game on this PC yet. RX_VK_RETIRED_HELD
ships on, as docs/dev/standards.md (Switches) asks of a switch's first push (=0 is main's way); the in-game A/B
(unset against =0 and main) in Still to test decides whether it stays. The figures in the source commit 12168bb8 were taken on the experiment
branch before main's own pass over the oldest given-back pools; they say nothing about this head.

Risks

What could break (on, the default): a retired pool missing from the list would keep its import (memory held longer, its
pages read as imported); one listed after it gave its import back would be given back twice. The test runs the real
retire_pool, memory_guest_imported and retired_imports_give_back with the switch off and on over the same 60,000
random steps in the three give-back modes (the queued imports freed as the GPU passes them) and compares every import
given back, figure, log line and answer, the list against the retired pools holding one (by address, in order), and
that retire_pool allocates no more with the list; directed cases check the wait mode's early give-back under heap
pressure and a pool bound again after it was retired. With =0, what changes from main: the extracted pool
is reached through its node, two counts are kept under pools_mu and logged with the imports line, and Pool is 8
bytes larger. Turn it off with RX_VK_RETIRED_HELD=0. Renderer code: the runtime is rebuilt; nothing changes
for players' saves, options or caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary At every part of a submission the give-back of retired imports (`retired_imports_give_back`) walked the retired pools, a deque of map nodes that only grows, and every free of the game's asked `memory_guest_imported`, which walked every retired pool too. Main already passes over the oldest retired pools given back; the walk of the rest stayed, and `memory_guest_imported` still walks them all. With this, `retire_pool` lists a retired pool that still has an import, in the order of retirement (`retired_held`, linked through the pools themselves: `Pool::held_next` and a tail pointer, so listing one allocates nothing), reaching the pool through its node once the table's node is extracted; `retired_imports_give_back` unlinks it as it gives the import back (the one place a retired pool loses its import), writing nothing for the pools it keeps. The give-back and `memory_guest_imported` walk that list instead. The same imports are given back, with the same budget figures and answers. Either way, a line after the `vk: imports:` line counts the retired pools each walk looked at (parts and calls), and Tracy builds time both walks in zones of their own. The result expected: less CPU time a submission when many pools have been retired; not measured yet. The switch: `RX_VK_RETIRED_HELD` (new, a kill switch, bool, its row in `gpu/vk/switches.def`), on by default as docs/dev/standards.md (Switches) asks of a switch's first push; read once; `=0` keeps main's walk, in the give-back and the free's check both. From 12168bb8 on `exp/x86-asm-sync` (the half of that commit that rebuilt the GPU-visible ranges in asm is not here). Read first: `retire_pool`, `retired_imports_give_back` and `memory_guest_imported` in `gpu/vk/vk_memory.cpp`, then `tests/test_retired_held.py`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head `e26cc20c` on main `9dd41326`. The checks ran at `91960bc2` on main `b62932a9`, the same commits before a rebase onto `9dd41326`, which added only lift files (#1905) that none of these checks reads. Light queue jobs `fb-2029-3` and `fb-2029-4` of this PC's job queue (the first found compile errors in the new fixtures, fixed before the second), each check in a hidden console through `tests/run_all.py --strict --exact --timeout 1200 --jobs 2`: `tests/test_retired_held.py`, `tests/test_import_reach.py` and `tests/test_switch_table.py` pass; `tests/test_guest_imported.py` and `tests/test_pending_guest_import.py` fail, with the same compile error (`import_reach` undeclared in their fixtures) on main @ 9dd41326 in the same job. At the test commit `cc8c828d` `tests/test_retired_held.py` fails, as expected (`retire_pool` allocates more with the vector list). The Windows game build's own compile of `gpu/vk/vk_memory.cpp` (syntax only) passes. Not run this round: every check `--changed` picks (a heavy batch), the Linux-target compile (the local tool could not read its build profile), `tests/test_vbytes.py` (hangs on this PC). **It has NOT run in the game on this PC yet.** **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest into Hyrule Field and back, then a long session (30 minutes or more, pools retire as scenes load) and a heavy view (Hyrule Field at dusk, the camera turned), on main @ 9dd41326, this branch with `RX_VK_RETIRED_HELD=0` and this branch unset (on), each warmed a minute, interleaved (ABC ABC ABC), expecting the same picture, no FATAL or device lost, the `vk: imports:` lines alike, fewer pools looked at in the `vk: retired walks` line unset than with `=0`, and average fps, 1% lows, median and p99 frame times and peak RAM and VRAM of this branch unset at least those of the other two; a difference beyond the runs' spread is a gain or a loss, one within it is no difference measured (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest into Hyrule Field and back five minutes and a long session, main, this branch with `RX_VK_RETIRED_HELD=0` and unset, warmed and interleaved, expecting the same picture and no FATAL or device lost (the test farm: linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest to Hyrule Field and back five minutes, main @ 9dd41326, this branch with RX_VK_RETIRED_HELD=0 and unset, warmed up, interleaved, the log, frame times and a screenshot) - Linux: build the renderer and run `python3 -I -B tests/test_retired_held.py`, expecting PASS (by hand) - A PC with pre-commit and ruff installed: `mise run test` and `mise run lint` at this head, expecting every failure to fail on main too and lint to pass (by hand; neither tool is installed on this PC) ## Measurements **Verdict:** not measured in play yet: no micro-benchmark of this port and no run in the game on this PC yet. `RX_VK_RETIRED_HELD` ships on, as docs/dev/standards.md (Switches) asks of a switch's first push (`=0` is main's way); the in-game A/B (unset against `=0` and main) in Still to test decides whether it stays. The figures in the source commit 12168bb8 were taken on the experiment branch before main's own pass over the oldest given-back pools; they say nothing about this head. ## Risks What could break (on, the default): a retired pool missing from the list would keep its import (memory held longer, its pages read as imported); one listed after it gave its import back would be given back twice. The test runs the real `retire_pool`, `memory_guest_imported` and `retired_imports_give_back` with the switch off and on over the same 60,000 random steps in the three give-back modes (the queued imports freed as the GPU passes them) and compares every import given back, figure, log line and answer, the list against the retired pools holding one (by address, in order), and that `retire_pool` allocates no more with the list; directed cases check the wait mode's early give-back under heap pressure and a pool bound again after it was retired. With `=0`, what changes from main: the extracted pool is reached through its node, two counts are kept under `pools_mu` and logged with the imports line, and `Pool` is 8 bytes larger. Turn it off with `RX_VK_RETIRED_HELD=0`. Renderer code: the runtime is rebuilt; nothing changes for players' saves, options or caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(vk): the submission walks only the retired pools still holding an import
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 17s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
3f6c6a2a4d
- retired_held: retire_pool lists a retired pool that has an import, in the order of retirement, and
  retired_imports_give_back drops it from there as it gives the import back (the one place a retired pool loses its
  import). The give-back at every part of a submission and memory_guest_imported at every free of the game's walk that
  list instead of retired_pools, a deque of map nodes that only grows, apart in the heap.
- Main has its own version of half of this: the give-back passes the oldest retired pools already given back (a static
  count) and walks the live pools only for its log line and the budget figures. The branch's list is ported beside it
  behind RX_VK_RETIRED_HELD (kill, on); =0 is main's walk, the give-back and the free's check both, an A/B in one build.
  memory_guest_imported still walked every retired pool on main.
- Branch's numbers (12168bb8, micro-benchmark with 300 live and 4,000 retired pools): 77.6 / 12.1 us -> 1.9 / 0.06 us a
  give-back, cold / warm cache; part of that (the live pools' sum) main removed already. In a Kokiri profile on the
  branch the walk took 6.7-19.6 us a submission with 70-300 retired pools, the list ~1.1 us. Not measured in play on main.
- Test: tests/test_retired_held.py cuts retire_pool, memory_guest_imported, retired_imports_give_back and the table's
  ways in and out, and runs them with the switch off and on over the same random 60,000 steps in the three give-back
  modes: the same imports given back, budget figures, log lines and import answers, and the list exactly the retired
  pools holding one. test_guest_imported, test_pending_guest_import and import_reach_test.cpp get the list's stand-ins.
  The half of 12168bb8 that rebuilt the GPU-visible ranges in asm is not in this commit.

Switch reads: the test also runs RX_VK_RETIRED_HELD as the source reads it, in fresh processes (unset, 0, 1, 2, off, each twice, the variable flipped after the first read: read once).

Assisted-by: Claude Code
Member

Possibly related, for context:

  • PR #1034 WIP: perf(vk): Stage 0 of the memory-sync redesign: the ceiling report, a content oracle for the write marks, and four unmarked writes fixed — Renderer memory-sync redesign overlaps vk_memory.cpp area
Possibly related, for context: - PR #1034 WIP: perf(vk): Stage 0 of the memory-sync redesign: the ceiling report, a content oracle for the write marks, and four unmarked writes fixed — Renderer memory-sync redesign overlaps vk_memory.cpp area
BeanBot left a comment

Recommendation: Request changes. The default path dereferences a pointer taken before its map node was extracted, while the node handle still owns the pool. Fix that lifetime and cover pressure-driven give-back in the fixture before using in-game results to choose the default.

The index can save CPU time during submissions and guest frees as retired records accumulate. It preserves retirement order and shares the give-back logic between both paths, at the cost of a second collection, heap growth during retirement, and pointer writes during submission.

@fix will do (6)

  1. L1 gpu/vk/vk_memory.cpp:4579: old comes from the live map before imported_take extracts its node. (more on the line)
  2. L2 tests/test_retired_held.py:187: The fixture advances GPU completion without reaping dead_imports. (more on the line)
  3. L3 (minor) tests/test_retired_held.py:140: Count, timestamp order and non-null handles do not establish exact membership. (more on the line)
  4. L4 (minor) tests/test_retired_held.py:294: Both fixture namespaces use the same refactored give-back body, so agreement misses regressions in the shared conditions. (more on the line)
  5. L5 (minor) gpu/vk/vk_memory.cpp:4579: Vector growth adds a fallible allocation under pools_mu after retirement has already changed the page table and moved the node. (more on the line)
  6. L6 (its part an edit can do) gpu/vk/vk_memory.cpp:5587: Add temporary timing and visit counts for both walks and record the vector's peak capacity. Skip pointer stores when a survivor is already in its destination slot.

For the author (1) (a run, a measurement or a decision)

  • L6 (minor) gpu/vk/vk_memory.cpp:5587: The planned median-only comparison misses tail latency and the cost when most retired imports are still held. (more on the line)

Checks: Still running: PR description / Description follows the template (pull_request_target), CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven. The commit reports 77.6 to 1.9 µs cold and 12.1 to 0.06 µs warm for 4,000 retired pools on branch commit 12168bb8. It also reports 6.7–19.6 µs down to about 1.1 µs per submission in Kokiri. The branch comparison predates optimizations already in the base. There are no timing or gameplay results for 3f6c6a2a against 75317e1f.

Other systems: Both walks hold pools_mu. Their timing can affect the replay thread and guest threads freeing pages. The give-back conditions are shared across immediate mode on Linux and Windows NVIDIA, grace mode on Windows AMD and Intel, and optional keep mode. Linux dma-buf and Windows host-pointer imports both rely on the guest-free check to keep backing pages intact. Mirror inheritance still uses the owning deque, and pending, evicted and background imports retain their existing checks. Static review found no changes to saves, audio, input, the renderer ABI or cache formats. Driver behavior, frame pacing and RAM/VRAM impact still need in-game validation, including on Steam Deck.

Switches: RX_VK_RETIRED_HELD is a developer kill switch, read once and on when unset. Set it to 0 to use the previous traversal in both paths. The switch table has a sorted row. On is the branch default for A/B testing. The shipping default remains unproven across affected hardware.

Reviewed: 3f6c6a2a4d against 75317e1f31: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template and docs/dev/standards.md. No docs/review-checklist.md or sibling Tooling checkout was present. Read the complete six-file diff and commit, all four changed test files in full, and the changed regions of vk_memory.cpp and switches.def with their surrounding code. Traced retirement callers, pool ownership and locking, completion and accounting, host frees, switch parsing and test compiler selection. Skimmed the earlier #391 results. The supplied PR description was the only source for this head’s recorded runs. There were no tester comments or prior reviews.; nothing run (a code review).

Checked and fine:

  • The new list accesses use the existing pool lock and the switch uses C++ thread-safe local static initialization.
  • Compaction preserves retirement order and writes only to slots already visited. Queued imports remain visible to guest frees through dead_imports until the completion check reaps them.
  • The new fixture uses synthetic handles, supports the runner's C++ override, and supplies an explicit switch environment to its fresh processes.
  • The diff contains no game-derived artifacts, generated files, third-party changes, or API changes requiring a version bump. The commit has the required Assisted-by trailer.

Testing: Read-only review. git diff --check passed. The author reports 82 of 96 Windows checks passed, 13 failures also seen on the base, and one timeout that passed on an isolated retry. The new fixture reportedly passed. The two older guest-import fixtures named in the base failures provide no passing evidence. No Linux or in-game result was supplied, and the listed CI checks were still running.

Overlaps and merge order: Merged #391 supplies the retired-prefix skip already in the base. Current main changes a separate switch-table row in #1870. No overlapping change requiring a merge order was found in the checkout.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The default path dereferences a pointer taken before its map node was extracted, while the node handle still owns the pool. Fix that lifetime and cover pressure-driven give-back in the fixture before using in-game results to choose the default. The index can save CPU time during submissions and guest frees as retired records accumulate. It preserves retirement order and shares the give-back logic between both paths, at the cost of a second collection, heap growth during retirement, and pointer writes during submission. **`@fix` will do (6)** 1. **L1** `gpu/vk/vk_memory.cpp:4579`: old comes from the live map before imported_take extracts its node. (more on the line) 2. **L2** `tests/test_retired_held.py:187`: The fixture advances GPU completion without reaping dead_imports. (more on the line) 3. **L3** (minor) `tests/test_retired_held.py:140`: Count, timestamp order and non-null handles do not establish exact membership. (more on the line) 4. **L4** (minor) `tests/test_retired_held.py:294`: Both fixture namespaces use the same refactored give-back body, so agreement misses regressions in the shared conditions. (more on the line) 5. **L5** (minor) `gpu/vk/vk_memory.cpp:4579`: Vector growth adds a fallible allocation under pools_mu after retirement has already changed the page table and moved the node. (more on the line) 6. **L6** (its part an edit can do) `gpu/vk/vk_memory.cpp:5587`: Add temporary timing and visit counts for both walks and record the vector's peak capacity. Skip pointer stores when a survivor is already in its destination slot. **For the author (1)** (a run, a measurement or a decision) - **L6** (minor) `gpu/vk/vk_memory.cpp:5587`: The planned median-only comparison misses tail latency and the cost when most retired imports are still held. (more on the line) **Checks:** Still running: `PR description / Description follows the template (pull_request_target)`, `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The commit reports 77.6 to 1.9 µs cold and 12.1 to 0.06 µs warm for 4,000 retired pools on branch commit 12168bb8. It also reports 6.7–19.6 µs down to about 1.1 µs per submission in Kokiri. The branch comparison predates optimizations already in the base. There are no timing or gameplay results for 3f6c6a2a against 75317e1f. **Other systems:** Both walks hold pools_mu. Their timing can affect the replay thread and guest threads freeing pages. The give-back conditions are shared across immediate mode on Linux and Windows NVIDIA, grace mode on Windows AMD and Intel, and optional keep mode. Linux dma-buf and Windows host-pointer imports both rely on the guest-free check to keep backing pages intact. Mirror inheritance still uses the owning deque, and pending, evicted and background imports retain their existing checks. Static review found no changes to saves, audio, input, the renderer ABI or cache formats. Driver behavior, frame pacing and RAM/VRAM impact still need in-game validation, including on Steam Deck. **Switches:** RX_VK_RETIRED_HELD is a developer kill switch, read once and on when unset. Set it to 0 to use the previous traversal in both paths. The switch table has a sorted row. On is the branch default for A/B testing. The shipping default remains unproven across affected hardware. **Reviewed:** 3f6c6a2a4d0a against 75317e1f31ff: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template and docs/dev/standards.md. No docs/review-checklist.md or sibling Tooling checkout was present. Read the complete six-file diff and commit, all four changed test files in full, and the changed regions of vk_memory.cpp and switches.def with their surrounding code. Traced retirement callers, pool ownership and locking, completion and accounting, host frees, switch parsing and test compiler selection. Skimmed the earlier #391 results. The supplied PR description was the only source for this head’s recorded runs. There were no tester comments or prior reviews.; nothing run (a code review). **Checked and fine:** - The new list accesses use the existing pool lock and the switch uses C++ thread-safe local static initialization. - Compaction preserves retirement order and writes only to slots already visited. Queued imports remain visible to guest frees through dead_imports until the completion check reaps them. - The new fixture uses synthetic handles, supports the runner's C++ override, and supplies an explicit switch environment to its fresh processes. - The diff contains no game-derived artifacts, generated files, third-party changes, or API changes requiring a version bump. The commit has the required Assisted-by trailer. **Testing:** Read-only review. git diff --check passed. The author reports 82 of 96 Windows checks passed, 13 failures also seen on the base, and one timeout that passed on an isolated retry. The new fixture reportedly passed. The two older guest-import fixtures named in the base failures provide no passing evidence. No Linux or in-game result was supplied, and the listed CI checks were still running. **Overlaps and merge order:** Merged #391 supplies the retired-prefix skip already in the base. Current main changes a separate switch-table row in #1870. No overlapping change requiring a merge order was found in the checkout. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -4565,6 +4576,7 @@ void retire_pool(std::map<uint64_t, Pool>::iterator it) {
if (old->mstate == Pool::MIRROR_ON) old->inherit_pending = true, old->retired_epoch = mirror_epoch;
pools_gen++;
retired_pools.push_back(imported_take(it));
if (old->memory && retired_held_on()) retired_held.push_back(old);
Member

L1: old comes from the live map before imported_take extracts its node. C++ permits that pointer to survive extraction, but accessing the element through it while a node handle owns it is undefined. The new default path reads old->memory at retirement and saves the pointer for subsequent frees and submissions. Reacquire the pointer from retired_pools.back().mapped() after extraction and use that pointer for the list and the existing post-extraction log.

**L1**: old comes from the live map before imported_take extracts its node. C++ permits that pointer to survive extraction, but accessing the element through it while a node handle owns it is undefined. The new default path reads old->memory at retirement and saves the pointer for subsequent frees and submissions. Reacquire the pointer from retired_pools.back().mapped() after extraction and use that pointer for the list and the existing post-extraction log.
Member

L5 (minor): Vector growth adds a fallible allocation under pools_mu after retirement has already changed the page table and moved the node. At the host commit limit, an optional index growth can make the renderer wait up to five seconds and then stop even when the owning deque had room. Make index allocation failure fall back to the deque scan under the same lock, or use bookkeeping that needs no separate allocation.

**L5** (minor): Vector growth adds a fallible allocation under pools_mu after retirement has already changed the page table and moved the node. At the host commit limit, an optional index growth can make the renderer wait up to five seconds and then stop even when the owning deque had room. Make index allocation failure fall back to the deque scan under the same lock, or use bookkeeping that needs no separate allocation.
@ -5571,1 +5584,4 @@
retired_alive++, retired_bytes += p.hi - p.lo;
return true;
};
if (retired_held_on()) { // (only the retired pools still holding an import, retired_held: those given back leave it)
Member

L6 (minor): The planned median-only comparison misses tail latency and the cost when most retired imports are still held. Run current main and the PR with the switch on and off in matched, warmed, interleaved in-game runs, including a long session, a heavy view and the affected Tier 1 hardware. Report both scan times, average FPS, 1% lows, median and p99 frame times, and peak RAM/VRAM. Record the author's own game run, drivers and results in Testing and Measurements.

**L6** (minor): The planned median-only comparison misses tail latency and the cost when most retired imports are still held. Run current main and the PR with the switch on and off in matched, warmed, interleaved in-game runs, including a long session, a heavy view and the affected Tier 1 hardware. Report both scan times, average FPS, 1% lows, median and p99 frame times, and peak RAM/VRAM. Record the author's own game run, drivers and results in Testing and Measurements.
@ -0,0 +137,4 @@
}
// (a pool is listed only with an import, and the give-back that takes one drops it in the same pass: so the list is
// exactly the retired pools with one, in the order they were retired)
CHECK(ref::retired_held.empty() && now::retired_held.size() == held);
Member

L3 (minor): Count, timestamp order and non-null handles do not establish exact membership. If two pools retire at the same timestamp, a duplicate of one can stand in for the other and pass these checks. Compare each index entry with the address of the next memory-owning node in retirement order. That invariant also lets the test drop the exact source-line checks for append and compaction.

**L3** (minor): Count, timestamp order and non-null handles do not establish exact membership. If two pools retire at the same timestamp, a duplicate of one can stand in for the other and pass these checks. Compare each index entry with the address of the next memory-owning node in retirement order. That invariant also lets the test drop the exact source-line checks for append and compaction.
@ -0,0 +184,4 @@
const uint64_t rec = below(3), lag = below(4), epochs = below(300) + 1, ms = below(4000);
const uint64_t used = (g_budget / 100) * (60 + below(40));
g_now += (int64_t)ms, g_used = used, g_heap_ok = below(8) != 0;
BOTH(mem_rec_value += rec, mem_completed = mem_rec_value - std::min(mem_rec_value, lag), mirror_epoch += epochs,
Member

L2: The fixture advances GPU completion without reaping dead_imports. Once about 1.12 GiB is queued in AT_ONCE, subtracting those bytes suppresses every later GRACE pressure probe at the fixture's 8 GiB budget and 99% maximum use. Reap completed entries and add a directed case that requires an early give-back under pressure, stops at the low watermark, and checks that the guest range is still reported imported until completion.

**L2**: The fixture advances GPU completion without reaping dead_imports. Once about 1.12 GiB is queued in AT_ONCE, subtracting those bytes suppresses every later GRACE pressure probe at the fixture's 8 GiB budget and 99% maximum use. Reap completed entries and add a directed case that requires an early give-back under pressure, stops at the low watermark, and checks that the guest range is still reported imported until completion.
@ -0,0 +291,4 @@
state = STATE.replace("@REACH@", reach)
fixture = (FIXTURE.replace("@STATE_REF@", state.replace("@HELD@", "false"))
.replace("@STATE_NOW@", state.replace("@HELD@", "true"))
.replace("@CODE@", "\n".join([retire, imported, give])))
Member

L4 (minor): Both fixture namespaces use the same refactored give-back body, so agreement misses regressions in the shared conditions. For example, dropping the last_value gate would queue an import too early on both sides and still compare equal. Add a directed expectation that an import with a completed retirement value and an outstanding latest binding stays held until the binding completes.

**L4** (minor): Both fixture namespaces use the same refactored give-back body, so agreement misses regressions in the shared conditions. For example, dropping the last_value gate would queue an import too early on both sides and still compare equal. Add a directed expectation that an import with a completed retirement value and an outstanding latest binding stays held until the binding completes.
siantm force-pushed perf/vk-retired-held from 3f6c6a2a4d
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 17s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to e26cc20c83
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 9s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-21 10:46:28 +00:00
Compare
Author
Contributor

Thank you for the review (#2029 (comment)). The branch is rebased on main @ 9dd41326 (the PR's own commit unchanged by the rebase, now 2efd763d), with a test commit cc8c828d and a fix commit e26cc20c; head e26cc20c. Point by point:

  • L1 (#2029 (comment)): right. retire_pool now reaches the pool through retired_pools.back().mapped() once imported_take has extracted its node, for the list and for the log line after it (e26cc20c). No test can tell the two pointers apart (same address); the fixture below runs the new code.
  • L2 (#2029 (comment)): right. The fixture now frees the queued imports as reap_mirrors does once the GPU is past them, at every part, so the wait mode's probe sees the settled use, and a directed case (fresh process, both sides) has 4 retired pools of 512 MB with the heap at 90 % of 8 GB: nothing goes before the 16th part's probe, then 3 go, oldest first, stopping once the 75 % watermark's worth is queued, the 4th is kept through the next probe, and the 3 stay reported imported by memory_guest_imported until the GPU passes them (cc8c828d).
  • L3 (#2029 (comment)): right. After every step the list is compared entry by entry, by address, with the retired pools that hold an import in retirement order (off: empty); the source-line checks are gone (cc8c828d).
  • L4 (#2029 (comment)): right. A directed case retires a pool at 20, completes 20, binds it again at 22: it keeps its import (and stays listed and reported imported) at 20 and 21 and is queued only at 22, on both sides (cc8c828d).
  • L5 (#2029 (comment)): right. The list is now linked through the pools (Pool::held_next and a tail pointer): listing a pool allocates nothing, and the give-back unlinks the pools it gives back without writing the ones it keeps (e26cc20c). The fixture checks that retire_pool allocates no more with the list than without it (cc8c828d: fails on the vector, passes now).
  • L6 (#2029 (comment) and the review's part an edit can do): the walks' counts (retired pools looked at by the give-back over its parts, and by the frees' check over its calls) are logged after the vk: imports: line and reset, either way the switch is set; Tracy builds time both walks in zones of their own (e26cc20c). There is no vector any more, so no peak capacity and no stores for pools kept. The in-game A/B you describe (main, =0, unset; a long session and a heavy view; Tier 1; average fps, 1% lows, median and p99 frame times, peak RAM and VRAM, and the walks line) is pending: it has not run in the game on this PC, and it is in Still to test.

RX_VK_RETIRED_HELD stays on by default (a kill switch, =0 is main's way), as docs/dev/standards.md (Switches) asks of a switch's first push; it is not measured in play yet, and the in-game A/B (unset against =0 and main) in Still to test decides whether it stays.

Tested here (Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23; queue jobs fb-2029-3, fb-2029-4, light): tests/test_retired_held.py, tests/test_import_reach.py and tests/test_switch_table.py pass; tests/test_guest_imported.py and tests/test_pending_guest_import.py fail, with the same compile error (import_reach undeclared in their fixtures) on main @ 9dd41326 in the same job. At the test commit cc8c828d tests/test_retired_held.py fails, as expected (retire_pool allocates more with the vector list). The Windows game build's own compile of gpu/vk/vk_memory.cpp (syntax only) passes. (Run at 91960bc2 on b62932a9; the push is the same commits rebased onto 9dd41326, which added only lift files.) Not run this round: every check --changed picks (a heavy batch), the Linux-target compile (the local tool could not read its build profile), tests/test_vbytes.py (hangs on this PC). The change has NOT run in the game on this PC yet. The description is updated.

Thank you for the review (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64389). The branch is rebased on main @ 9dd41326 (the PR's own commit unchanged by the rebase, now 2efd763d), with a test commit cc8c828d and a fix commit e26cc20c; head e26cc20c. Point by point: - **L1** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64383): right. `retire_pool` now reaches the pool through `retired_pools.back().mapped()` once `imported_take` has extracted its node, for the list and for the log line after it (e26cc20c). No test can tell the two pointers apart (same address); the fixture below runs the new code. - **L2** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64384): right. The fixture now frees the queued imports as `reap_mirrors` does once the GPU is past them, at every part, so the wait mode's probe sees the settled use, and a directed case (fresh process, both sides) has 4 retired pools of 512 MB with the heap at 90 % of 8 GB: nothing goes before the 16th part's probe, then 3 go, oldest first, stopping once the 75 % watermark's worth is queued, the 4th is kept through the next probe, and the 3 stay reported imported by `memory_guest_imported` until the GPU passes them (cc8c828d). - **L3** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64385): right. After every step the list is compared entry by entry, by address, with the retired pools that hold an import in retirement order (off: empty); the source-line checks are gone (cc8c828d). - **L4** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64386): right. A directed case retires a pool at 20, completes 20, binds it again at 22: it keeps its import (and stays listed and reported imported) at 20 and 21 and is queued only at 22, on both sides (cc8c828d). - **L5** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64387): right. The list is now linked through the pools (`Pool::held_next` and a tail pointer): listing a pool allocates nothing, and the give-back unlinks the pools it gives back without writing the ones it keeps (e26cc20c). The fixture checks that `retire_pool` allocates no more with the list than without it (cc8c828d: fails on the vector, passes now). - **L6** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2029#issuecomment-64388 and the review's part an edit can do): the walks' counts (retired pools looked at by the give-back over its parts, and by the frees' check over its calls) are logged after the `vk: imports:` line and reset, either way the switch is set; Tracy builds time both walks in zones of their own (e26cc20c). There is no vector any more, so no peak capacity and no stores for pools kept. The in-game A/B you describe (main, `=0`, unset; a long session and a heavy view; Tier 1; average fps, 1% lows, median and p99 frame times, peak RAM and VRAM, and the walks line) is pending: it has not run in the game on this PC, and it is in Still to test. `RX_VK_RETIRED_HELD` stays **on by default** (a kill switch, `=0` is main's way), as docs/dev/standards.md (Switches) asks of a switch's first push; it is not measured in play yet, and the in-game A/B (unset against `=0` and main) in Still to test decides whether it stays. Tested here (Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23; queue jobs fb-2029-3, fb-2029-4, light): `tests/test_retired_held.py`, `tests/test_import_reach.py` and `tests/test_switch_table.py` pass; `tests/test_guest_imported.py` and `tests/test_pending_guest_import.py` fail, with the same compile error (`import_reach` undeclared in their fixtures) on main @ 9dd41326 in the same job. At the test commit `cc8c828d` `tests/test_retired_held.py` fails, as expected (`retire_pool` allocates more with the vector list). The Windows game build's own compile of `gpu/vk/vk_memory.cpp` (syntax only) passes. (Run at `91960bc2` on b62932a9; the push is the same commits rebased onto 9dd41326, which added only lift files.) Not run this round: every check `--changed` picks (a heavy batch), the Linux-target compile (the local tool could not read its build profile), `tests/test_vbytes.py` (hangs on this PC). The change has NOT run in the game on this PC yet. The description is updated.
Author
Contributor

@Beanstalk This makes the renderer give back retired imports with walks of the retired pools at each submission part and each free (gpu/vk/vk_memory.cpp), on by default; RX_VK_RETIRED_HELD=0 is main's way. This head is on main 9dd41326: please compare with main at that merge base. Please play Kokiri Forest to Hyrule Field and back for five minutes, then one longer session of fifteen minutes, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_RETIRED_HELD=0, with a picture in each scene compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, device lost or FATAL line; the log's "vk: imports:" lines alike on every side; unset, the "vk: retired walks" line shows fewer pools looked at than with it off; frame time p99 and peak VRAM no worse than main's. Please report those two lines.

@Beanstalk This makes the renderer give back retired imports with walks of the retired pools at each submission part and each free (gpu/vk/vk_memory.cpp), on by default; RX_VK_RETIRED_HELD=0 is main's way. This head is on main 9dd41326: please compare with main at that merge base. Please play Kokiri Forest to Hyrule Field and back for five minutes, then one longer session of fifteen minutes, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_RETIRED_HELD=0, with a picture in each scene compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, device lost or FATAL line; the log's "vk: imports:" lines alike on every side; unset, the "vk: retired walks" line shows fewer pools looked at than with it off; frame time p99 and peak VRAM no worse than main's. Please report those two lines.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 9s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-retired-held:siantm-perf/vk-retired-held'
git switch 'siantm-perf/vk-retired-held'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
MagicBeanDev/Longshot!2029
No description provided.