perf(shader): reuse an evicted memo result's bindings for the next miss #9049

Closed
EdouardSence wants to merge 4 commits from upstream-pr/9049 into main
EdouardSence commented 2026-10-21 10:52:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-21T10:52:12Z.


What

In ASTRO BOT's Sky Garden, the queue worker thread is at ~99 % and bounds the frame. The Recompile(request, capture) result memo hits only ~6.5 % of the time there: about 35k misses per second, nearly every one evicting an entry. Every miss builds a new RecompileResult. Its bindings are copied from the binding plan with all of each DescriptorBinding's vectors, and the evicted result is destroyed with all of its vectors on the same thread. In an eu-stack sample of the worker (120 samples), ~18 % of samples were in ~RecompileResult under materializePreparedMemoized, and malloc/free showed up under Materialize and Populate too. With LD_PRELOAD of jemalloc the same build ran ~8 % faster, so allocation is a real share of the frame there.

  • On a miss, materializePreparedMemoized now picks the set's least recently used entry before materializing. When the memo holds the only reference to it (use_count() == 1 under the source mutex, which every other lookup also takes), the entry is taken out of the set and its bindings vector is passed to materializeResult.
  • DescriptorBindingBuilder::Populate copy-assigns each plan binding into the allocation's existing elements, then resizes to the plan's size, instead of building a new vector. The vectors in a reused element keep their storage. An empty allocation gives the same result as before.
  • Results with other owners (a queued draw still holding one) are evicted as before.
  • The eviction counter of APS5_PROFILE_DRAW's [recompile] result memo line also counts these entries.

Tested

  • Linux (CachyOS, kernel 7.2.10), GCC, -DBUILD_TESTING=ON: ctest 1786/1792 with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 on the RX 9070 XT. The 6 failures (agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation (segfault), net_dontwait_blocking_send, _sendto, _sendmsg) fail the same way on main 2abfb1beb in this environment.
  • Focused tests with ctest -V and the same variables, on main and on this branch: agc_shader_disk_cache, agc_shader_memory, agc_driver_graphics, agc_driver_tests and the agc_driver_draw* tests (17 tests) pass on both. Neither log has a VUID- line or was not found but was requested by env var VK_INSTANCE_LAYERS.
  • verifyBindingPlanSelection (agc_shader_disk_cache) now also populates the selected plan into an allocation that still holds the full plan's four bindings, and checks that the result equals a fresh populate.
  • Speed: ASTRO BOT PPSA21567 01.019.000, Sky Garden (-lvl underwater_aerial_garden), headless gamescope 3840×2160, no input, APS5_TRACE_SECONDS=90:50, APS5_NO_SNAPSHOT_CHECK=1. Both builds also ran with APS5_HOST_IMPORT_MIB=11815, because main without #7844 thrashes textures in this level on a 16 GB card. Each build had a warm-up run, then the runs were interleaved.
Build presents (50 s) frame p50 / p90 / p99 ms GPU busy ms/present Driver.Draw.shader_compile_and_link ms/frame
main 2abfb1beb, warm-up 194 252.2 / 272.0 / 350.6 131.1 140.0
this PR 7fcf71555, warm-up 204 240.3 / 258.5 / 266.8 130.3 113.3
main, run 1 192 255.5 / 273.0 / 379.8 130.3 137.2
this PR, run 1 209 237.5 / 254.8 / 260.8 131.3 110.3
main, run 2 192 260.2 / 273.7 / 402.2 130.4 138.7
this PR, run 2 208 237.2 / 254.6 / 260.3 129.9 110.3

This PR is about 8 % faster at p50 here, and p99 drops from 380-402 ms to ~261 ms. GPU time is unchanged. In the traces, Shader.DrawStage goes from 123.4 to 96.8 ms per frame. The worker stays at ~99 %, so the draw cost still bounds the frame.

Summary lines (run 1 of each). Traces of both run 1s: main, this PR. Both traces dropped events after a few seconds on the worker (trace_dropped); the frame times come from the presents.

{"commit":"2abfb1beb4dd","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"11815","APS5_NO_SNAPSHOT_CHECK":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"90:50"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch3.1","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31228,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 90:50","first_present":1601,"ms":50091.668},"presents":192,"frame_ms":{"p50":255.485,"p90":273.049,"p99":379.795,"max":562.272},"gpu_busy_ms_per_present":130.340,"worker_busy_pct":{"queue worker 0x0":99.321,"queue worker 0x40":99.504,"queue worker 0x48":99.349,"queue worker 0x46":0.840,"queue worker 0x3a":0.078},"top_phases_ms_per_frame":{"Driver.Packet":779.517,"Driver.Packet.memory_wait":492.248,"Driver.Packet.draw":198.854,"Driver.Draw":197.899,"Graphics.Draw":154.105,"Driver.Draw.shader_compile_and_link":137.224,"Graphics.Draw.draw_and_resource_release":133.193,"Shader.DrawStage":123.446},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.259,"events_lost":3623330,"totals_full":false},"draw committer":{"events_full_after_s":9.812,"events_lost":1080694,"totals_full":false}},"trace":"aps5-trace-2abfb1beb4dd-758987.json.gz"}
{"commit":"7fcf715559eb","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"11815","APS5_NO_SNAPSHOT_CHECK":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"90:50"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch3.1","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31228,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 90:50","first_present":898,"ms":50224.935},"presents":209,"frame_ms":{"p50":237.486,"p90":254.840,"p99":260.847,"max":262.016},"gpu_busy_ms_per_present":131.252,"worker_busy_pct":{"queue worker 0x0":99.238,"queue worker 0x40":99.617,"queue worker 0x48":99.519,"queue worker 0x46":0.908,"queue worker 0x3a":0.140},"top_phases_ms_per_frame":{"Driver.Packet":718.817,"Driver.Packet.memory_wait":448.867,"Driver.Packet.draw":179.435,"Driver.Draw":178.494,"Graphics.Draw":145.812,"Graphics.Draw.draw_and_resource_release":125.790,"Driver.Draw.shader_compile_and_link":110.315,"Shader.DrawStage":96.817},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.773,"events_lost":3198830,"totals_full":false},"draw committer":{"events_full_after_s":9.461,"events_lost":1128611,"totals_full":false}},"trace":"aps5-trace-7fcf715559eb-760875.json.gz"}
  • Not tested: Windows, NVIDIA, Intel, other titles.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT, RADV Mesa 26.2.4, Linux 7.2.10 (CachyOS)
  • AI-assisted: yes

Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4950377167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-21T10:52:12Z. --- ### What In ASTRO BOT's Sky Garden, the queue worker thread is at ~99 % and bounds the frame. The `Recompile(request, capture)` result memo hits only ~6.5 % of the time there: about 35k misses per second, nearly every one evicting an entry. Every miss builds a new `RecompileResult`. Its `bindings` are copied from the binding plan with all of each `DescriptorBinding`'s vectors, and the evicted result is destroyed with all of its vectors on the same thread. In an `eu-stack` sample of the worker (120 samples), ~18 % of samples were in `~RecompileResult` under `materializePreparedMemoized`, and malloc/free showed up under `Materialize` and `Populate` too. With `LD_PRELOAD` of jemalloc the same build ran ~8 % faster, so allocation is a real share of the frame there. - On a miss, `materializePreparedMemoized` now picks the set's least recently used entry before materializing. When the memo holds the only reference to it (`use_count() == 1` under the source mutex, which every other lookup also takes), the entry is taken out of the set and its `bindings` vector is passed to `materializeResult`. - `DescriptorBindingBuilder::Populate` copy-assigns each plan binding into the allocation's existing elements, then resizes to the plan's size, instead of building a new vector. The vectors in a reused element keep their storage. An empty allocation gives the same result as before. - Results with other owners (a queued draw still holding one) are evicted as before. - The eviction counter of `APS5_PROFILE_DRAW`'s `[recompile] result memo` line also counts these entries. ### Tested - Linux (CachyOS, kernel 7.2.10), GCC, `-DBUILD_TESTING=ON`: ctest 1786/1792 with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1` on the RX 9070 XT. The 6 failures (`agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` (segfault), `net_dontwait_blocking_send`, `_sendto`, `_sendmsg`) fail the same way on `main` 2abfb1beb in this environment. - Focused tests with `ctest -V` and the same variables, on `main` and on this branch: `agc_shader_disk_cache`, `agc_shader_memory`, `agc_driver_graphics`, `agc_driver_tests` and the `agc_driver_draw*` tests (17 tests) pass on both. Neither log has a `VUID-` line or `was not found but was requested by env var VK_INSTANCE_LAYERS`. - `verifyBindingPlanSelection` (`agc_shader_disk_cache`) now also populates the selected plan into an allocation that still holds the full plan's four bindings, and checks that the result equals a fresh populate. - Speed: ASTRO BOT PPSA21567 01.019.000, Sky Garden (`-lvl underwater_aerial_garden`), headless gamescope 3840×2160, no input, `APS5_TRACE_SECONDS=90:50`, `APS5_NO_SNAPSHOT_CHECK=1`. Both builds also ran with `APS5_HOST_IMPORT_MIB=11815`, because `main` without #7844 thrashes textures in this level on a 16 GB card. Each build had a warm-up run, then the runs were interleaved. | Build | presents (50 s) | frame p50 / p90 / p99 ms | GPU busy ms/present | `Driver.Draw.shader_compile_and_link` ms/frame | |---|---:|---|---:|---:| | `main` 2abfb1beb, warm-up | 194 | 252.2 / 272.0 / 350.6 | 131.1 | 140.0 | | this PR 7fcf71555, warm-up | 204 | 240.3 / 258.5 / 266.8 | 130.3 | 113.3 | | `main`, run 1 | 192 | 255.5 / 273.0 / 379.8 | 130.3 | 137.2 | | this PR, run 1 | 209 | 237.5 / 254.8 / 260.8 | 131.3 | 110.3 | | `main`, run 2 | 192 | 260.2 / 273.7 / 402.2 | 130.4 | 138.7 | | this PR, run 2 | 208 | 237.2 / 254.6 / 260.3 | 129.9 | 110.3 | This PR is about 8 % faster at p50 here, and p99 drops from 380-402 ms to ~261 ms. GPU time is unchanged. In the traces, `Shader.DrawStage` goes from 123.4 to 96.8 ms per frame. The worker stays at ~99 %, so the draw cost still bounds the frame. Summary lines (run 1 of each). Traces of both run 1s: [main](https://github.com/EdouardSence/AnyPS5/releases/download/perf-traces-recycle-bindings/aps5-trace-2abfb1beb4dd-758987.json.gz), [this PR](https://github.com/EdouardSence/AnyPS5/releases/download/perf-traces-recycle-bindings/aps5-trace-7fcf715559eb-760875.json.gz). Both traces dropped events after a few seconds on the worker (`trace_dropped`); the frame times come from the presents. ```json {"commit":"2abfb1beb4dd","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"11815","APS5_NO_SNAPSHOT_CHECK":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"90:50"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch3.1","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31228,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 90:50","first_present":1601,"ms":50091.668},"presents":192,"frame_ms":{"p50":255.485,"p90":273.049,"p99":379.795,"max":562.272},"gpu_busy_ms_per_present":130.340,"worker_busy_pct":{"queue worker 0x0":99.321,"queue worker 0x40":99.504,"queue worker 0x48":99.349,"queue worker 0x46":0.840,"queue worker 0x3a":0.078},"top_phases_ms_per_frame":{"Driver.Packet":779.517,"Driver.Packet.memory_wait":492.248,"Driver.Packet.draw":198.854,"Driver.Draw":197.899,"Graphics.Draw":154.105,"Driver.Draw.shader_compile_and_link":137.224,"Graphics.Draw.draw_and_resource_release":133.193,"Shader.DrawStage":123.446},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.259,"events_lost":3623330,"totals_full":false},"draw committer":{"events_full_after_s":9.812,"events_lost":1080694,"totals_full":false}},"trace":"aps5-trace-2abfb1beb4dd-758987.json.gz"} {"commit":"7fcf715559eb","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"11815","APS5_NO_SNAPSHOT_CHECK":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"90:50"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch3.1","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31228,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 90:50","first_present":898,"ms":50224.935},"presents":209,"frame_ms":{"p50":237.486,"p90":254.840,"p99":260.847,"max":262.016},"gpu_busy_ms_per_present":131.252,"worker_busy_pct":{"queue worker 0x0":99.238,"queue worker 0x40":99.617,"queue worker 0x48":99.519,"queue worker 0x46":0.908,"queue worker 0x3a":0.140},"top_phases_ms_per_frame":{"Driver.Packet":718.817,"Driver.Packet.memory_wait":448.867,"Driver.Packet.draw":179.435,"Driver.Draw":178.494,"Graphics.Draw":145.812,"Graphics.Draw.draw_and_resource_release":125.790,"Driver.Draw.shader_compile_and_link":110.315,"Shader.DrawStage":96.817},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.773,"events_lost":3198830,"totals_full":false},"draw committer":{"events_full_after_s":9.461,"events_lost":1128611,"totals_full":false}},"trace":"aps5-trace-7fcf715559eb-760875.json.gz"} ``` - Not tested: Windows, NVIDIA, Intel, other titles. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 9070 XT, RADV Mesa 26.2.4, Linux 7.2.10 (CachyOS) - [x] AI-assisted: yes *Tested and written by Claude (AI assistant) on a contributor's machine.* AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
EdouardSence commented 2026-10-21 12:52:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-21T12:52:23Z.


Checked the files the overlap comment could not compare, against the diffs of those 25 pull requests. No other pull request changes the result memo (materializePreparedMemoized, ResultMemoEntry) or Populate's binding loop.

Four touch the line this PR changes in Recompiler.cpp, the materializeResult signature:

  • #8564 and #9020 rename its snapshot parameter to captured.
  • #6947 and #7642 (drafts) add a UsedBindingPlan* usedPlan = nullptr parameter.

Each is a one-line textual conflict. Whichever lands second keeps both changes; the parameters are independent. No Depends on needed.

Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316465250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6316465250). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-21T12:52:23Z. --- Checked the files the overlap comment could not compare, against the diffs of those 25 pull requests. No other pull request changes the result memo (`materializePreparedMemoized`, `ResultMemoEntry`) or `Populate`'s binding loop. Four touch the line this PR changes in `Recompiler.cpp`, the `materializeResult` signature: - #8564 and #9020 rename its `snapshot` parameter to `captured`. - #6947 and #7642 (drafts) add a `UsedBindingPlan* usedPlan = nullptr` parameter. Each is a one-line textual conflict. Whichever lands second keeps both changes; the parameters are independent. No `Depends on` needed. *Tested and written by Claude (AI assistant) on a contributor's machine.* AI-assisted: yes
ycbuzi commented 2026-10-21 17:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:51:18Z.


Windows run of 7fcf715559 merged onto main 745b394629 (efc0236650, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON. RTX 4070 SUPER, NVIDIA 616.92 (ANYPS5_GPU=4070).

Built agc_shader_disk_cache_tests with no errors or warnings. ctest --repeat until-fail:2 on the 15 tests these executables register on Windows: all pass on both repeats. These are the agc_shader_disk_cache, agc_shader_cache_housekeeping_* and agc_shader_prebuilt_discovery_* tests. Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322742699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6322742699). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T17:51:18Z. --- Windows run of 7fcf715559 merged onto `main` 745b394629 (efc0236650, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. RTX 4070 SUPER, NVIDIA 616.92 (`ANYPS5_GPU=4070`). Built `agc_shader_disk_cache_tests` with no errors or warnings. `ctest --repeat until-fail:2` on the 15 tests these executables register on Windows: all pass on both repeats. These are the `agc_shader_disk_cache`, `agc_shader_cache_housekeeping_*` and `agc_shader_prebuilt_discovery_*` tests. Not run: a title.
teepean commented 2026-10-21 19:31:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-21T19:31:03Z.


@EdouardSence a Linux/NVIDIA data point on Stray (PPSA02100). It was measured on my stack, not on plain main, with a replacement allocator, so take it as one data point.

Setup

  • CachyOS (kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release.
  • Base: my stack on main 1ff5c8ac5c (showcase/stray-stack, 27dbc2891f). 7fcf715559 cherry-picks onto it cleanly.
  • Stray at the start of the Dead City chapter, 3840x2160, stock engine.ini, scripted input.
  • tcmalloc (gperftools 2.18) or jemalloc 5.4.0 preloaded, as a 2x2 with and without this PR, four rounds in a balanced order.

FPS (mean of four runs)

tcmalloc jemalloc
without #9049 17.93 18.57
with #9049 17.60 17.83
  • Across both allocators, the PR is -0.59 FPS (-3.2 %), and slower in all four rounds.
  • [recompile] result memo with APS5_PROFILE_DRAW=1 (one run each, tcmalloc, about 100k misses per 10 s in both): Populate takes 1.9 us per miss without the PR and 2.4 us with it.
  • Part of that difference is where the frees are counted. Without the PR, the evicted result is freed when the new one is inserted, outside Populate's timer.
  • My guess at the rest: GuestBuffers, GuestSamplers and ShaderData bindings still move-assign a freshly built vector, so their old storage is freed, not reused. The recycled entry is also the least recently used one, so its memory is likely cold in the cache. With tcmalloc or jemalloc, a fresh small allocation costs less than that.

Tests and output

  • agc_shader_disk_cache_tests passes, including the new check.
  • The focused draw tests I run on my stack give the same results with and without the PR.
  • Frames 26-39 of a 40-frame dump match the stack without the PR (mean difference at most 0.7).

Your -8 % came from main with glibc, where malloc and free cost more, so the result may well differ there. If it helps, I can measure main + #9049 with glibc on Stray.

AI-assisted: yes (text with Claude Code; the numbers are from my machine).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324724758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6324724758). Originally posted by [teepean](https://github.com/teepean) on 2026-10-21T19:31:03Z. --- @EdouardSence a Linux/NVIDIA data point on Stray (PPSA02100). It was measured on my stack, not on plain `main`, with a replacement allocator, so take it as one data point. **Setup** - CachyOS (kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release. - Base: my stack on `main` 1ff5c8ac5c ([`showcase/stray-stack`](https://github.com/teepean/AnyPS5/tree/showcase/stray-stack), 27dbc2891f). 7fcf715559 cherry-picks onto it cleanly. - Stray at the start of the Dead City chapter, 3840x2160, stock `engine.ini`, scripted input. - tcmalloc (gperftools 2.18) or jemalloc 5.4.0 preloaded, as a 2x2 with and without this PR, four rounds in a balanced order. **FPS (mean of four runs)** | | tcmalloc | jemalloc | |---|---|---| | without #9049 | 17.93 | 18.57 | | with #9049 | 17.60 | 17.83 | - Across both allocators, the PR is -0.59 FPS (-3.2 %), and slower in all four rounds. - `[recompile] result memo` with `APS5_PROFILE_DRAW=1` (one run each, tcmalloc, about 100k misses per 10 s in both): Populate takes 1.9 us per miss without the PR and 2.4 us with it. - Part of that difference is where the frees are counted. Without the PR, the evicted result is freed when the new one is inserted, outside Populate's timer. - My guess at the rest: GuestBuffers, GuestSamplers and ShaderData bindings still move-assign a freshly built vector, so their old storage is freed, not reused. The recycled entry is also the least recently used one, so its memory is likely cold in the cache. With tcmalloc or jemalloc, a fresh small allocation costs less than that. **Tests and output** - `agc_shader_disk_cache_tests` passes, including the new check. - The focused draw tests I run on my stack give the same results with and without the PR. - Frames 26-39 of a 40-frame dump match the stack without the PR (mean difference at most 0.7). Your -8 % came from `main` with glibc, where `malloc` and `free` cost more, so the result may well differ there. If it helps, I can measure `main` + #9049 with glibc on Stray. AI-assisted: yes (text with Claude Code; the numbers are from my machine).
EdouardSence commented 2026-10-22 07:53:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T07:53:54Z.


@teepean thanks for the Stray runs and the reading. Your guess about the move-assigned vectors was right, so I pushed edc95643a: GuestBuffersDescriptor and GuestSamplersDescriptor now fill the binding's existing guestDescriptor instead of returning a new vector, so a recycled binding keeps that storage too. ShaderData still moves its vector in.

Sky Garden A/B, ASTRO BOT PPSA21567 01.019.000, Ryzen 7 7800X3D, RX 9070 XT (RADV Mesa 26.2.4), CachyOS. Headless gamescope 3840x2160, no input, APS5_TRACE_SECONDS=90:50, APS5_HOST_IMPORT_MIB=11815, warm shader cache, all on base 2abfb1beb. Two rounds, arms interleaved. Frame p50 in ms:

Build glibc r1 / r2 jemalloc 5.4.0 r1 / r2
main 267.8 / 259.8 239.2 / 232.5
previous head 7fcf71555 246.2 / 251.2 240.7 / 220.6
new head edc95643a 243.4 / 240.9 222.0 / 221.8

On this machine and scene, the previous head was not slower with jemalloc (its round 1 is the noisy one). The new head is about 8 % faster than main with glibc and about 6 % faster with jemalloc. Your Stray scene on NVIDIA may still behave differently, for example because the LRU victim is cold in the cache, as you said. If you have time, a run of the new head on your stack would show whether this change recovers the 3 %.

tools/check_conventions.py passes, and so do the 7 agc_shader_disk_cache*/housekeeping/prebuilt tests. #9177 (milescoviello) adds a reserve in GuestSamplersDescriptor, which this commit also touches, so whichever PR lands second needs a small rebase.

Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335694858 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6335694858). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-22T07:53:54Z. --- @teepean thanks for the Stray runs and the reading. Your guess about the move-assigned vectors was right, so I pushed edc95643a: `GuestBuffersDescriptor` and `GuestSamplersDescriptor` now fill the binding's existing `guestDescriptor` instead of returning a new vector, so a recycled binding keeps that storage too. `ShaderData` still moves its vector in. Sky Garden A/B, ASTRO BOT PPSA21567 01.019.000, Ryzen 7 7800X3D, RX 9070 XT (RADV Mesa 26.2.4), CachyOS. Headless gamescope 3840x2160, no input, `APS5_TRACE_SECONDS=90:50`, `APS5_HOST_IMPORT_MIB=11815`, warm shader cache, all on base 2abfb1beb. Two rounds, arms interleaved. Frame p50 in ms: | Build | glibc r1 / r2 | jemalloc 5.4.0 r1 / r2 | |---|---|---| | `main` | 267.8 / 259.8 | 239.2 / 232.5 | | previous head 7fcf71555 | 246.2 / 251.2 | 240.7 / 220.6 | | new head edc95643a | 243.4 / 240.9 | 222.0 / 221.8 | On this machine and scene, the previous head was not slower with jemalloc (its round 1 is the noisy one). The new head is about 8 % faster than `main` with glibc and about 6 % faster with jemalloc. Your Stray scene on NVIDIA may still behave differently, for example because the LRU victim is cold in the cache, as you said. If you have time, a run of the new head on your stack would show whether this change recovers the 3 %. `tools/check_conventions.py` passes, and so do the 7 `agc_shader_disk_cache*`/housekeeping/prebuilt tests. #9177 (milescoviello) adds a `reserve` in `GuestSamplersDescriptor`, which this commit also touches, so whichever PR lands second needs a small rebase. *Tested and written by Claude (AI assistant) on a contributor's machine.* AI-assisted: yes
ycbuzi commented 2026-10-22 08:34:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-22T08:34:31Z.


Windows run of edc95643a1, the update since my earlier run, merged onto main d6eafa54d0 (0edab22f56, clean). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 616.92 (ANYPS5_GPU=4070, ANYPS5_REQUIRE_VULKAN=1).

Built libSceAgcDriver and agc_shader_disk_cache_tests with no errors or warnings. ctest --repeat until-fail:2 on the 15 tests that executable registers on Windows (agc_shader_disk_cache, agc_shader_cache_housekeeping_* and agc_shader_prebuilt_discovery_*): all pass on both repeats, none skipped. Not run: a frame-time measurement, a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336427143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6336427143). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-22T08:34:31Z. --- Windows run of edc95643a1, the update since my earlier run, merged onto `main` d6eafa54d0 (0edab22f56, clean). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 616.92 (`ANYPS5_GPU=4070`, `ANYPS5_REQUIRE_VULKAN=1`). Built `libSceAgcDriver` and `agc_shader_disk_cache_tests` with no errors or warnings. `ctest --repeat until-fail:2` on the 15 tests that executable registers on Windows (`agc_shader_disk_cache`, `agc_shader_cache_housekeeping_*` and `agc_shader_prebuilt_discovery_*`): all pass on both repeats, none skipped. Not run: a frame-time measurement, a title.
teepean commented 2026-10-22 12:05:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-22T12:05:47Z.


@EdouardSence thanks, here is edc95643a1 on our stack. Short version: the loss is gone; it is level with our base now.

Setup

  • Linux (CachyOS, kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release, jemalloc preloaded.
  • Base: our Stray stack (upstream main 1ff5c8ac5c plus our draw-committer changes and a few open PRs, #9177 among them). The PR side is the same base plus 7fcf715559 and edc95643a1. The only conflict was #9177's reserve in GuestSamplersDescriptor, which I kept after the new clear().
  • Stray at the start of the Dead City chapter, 3840x2160, stock engine.ini, scripted input, one run at a time, mean FPS over seconds 180-240.
  • The −3.2 % I posted earlier was 7fcf715559 on an older base of ours (four rounds).

FPS (8 rounds, order alternating)

runs mean
base 18.3 18.2 18.0 17.8 18.5 18.3 18.6 18.6 18.29
base + 7fcf715559 + edc95643a1 17.8 18.8 17.8 18.3 19.1 18.0 18.9 18.1 18.35 (+0.3 %)

The PR side won 4 of 8 rounds. Run-to-run spread here is 0.3-0.5 FPS, so this is level within noise. Filling the reused binding's storage removed what cost us before.

Checks

  • Our verify run (proof memo, draw snapshots and stage-instance results checked against the full paths): 6.22M memo hits, 0 wrong; 670,723 stage-instance results compared, 0 differing.
  • One run of the PR side ended at 184 s: the process exited with nothing in the log, no error or assertion. Its retry ran normally. I haven't seen that before on this stack, but one run is not enough to tie it to this PR. I'll mention it if it happens again.

AI-assisted: yes (text with Claude Code; the numbers are from my machine).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340308436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6340308436). Originally posted by [teepean](https://github.com/teepean) on 2026-10-22T12:05:47Z. --- @EdouardSence thanks, here is edc95643a1 on our stack. Short version: the loss is gone; it is level with our base now. **Setup** - Linux (CachyOS, kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release, jemalloc preloaded. - Base: our Stray stack (upstream `main` 1ff5c8ac5c plus our draw-committer changes and a few open PRs, #9177 among them). The PR side is the same base plus 7fcf715559 and edc95643a1. The only conflict was #9177's `reserve` in `GuestSamplersDescriptor`, which I kept after the new `clear()`. - Stray at the start of the Dead City chapter, 3840x2160, stock `engine.ini`, scripted input, one run at a time, mean FPS over seconds 180-240. - The −3.2 % I posted earlier was 7fcf715559 on an older base of ours (four rounds). **FPS** (8 rounds, order alternating) | | runs | mean | |---|---|---| | base | 18.3 18.2 18.0 17.8 18.5 18.3 18.6 18.6 | 18.29 | | base + 7fcf715559 + edc95643a1 | 17.8 18.8 17.8 18.3 19.1 18.0 18.9 18.1 | 18.35 (+0.3 %) | The PR side won 4 of 8 rounds. Run-to-run spread here is 0.3-0.5 FPS, so this is level within noise. Filling the reused binding's storage removed what cost us before. **Checks** - Our verify run (proof memo, draw snapshots and stage-instance results checked against the full paths): 6.22M memo hits, 0 wrong; 670,723 stage-instance results compared, 0 differing. - One run of the PR side ended at 184 s: the process exited with nothing in the log, no error or assertion. Its retry ran normally. I haven't seen that before on this stack, but one run is not enough to tie it to this PR. I'll mention it if it happens again. AI-assisted: yes (text with Claude Code; the numbers are from my machine).
EdouardSence commented 2026-10-22 12:11:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T12:11:35Z.


@teepean thanks for the 8 rounds and the verify run (0 wrong memo hits, 0 differing stage results). Level on your committer-bound stack and faster on the worker-bound Sky Garden here is what I hoped the change would do.

About the exit at 184 s: none of my Sky Garden runs on either head exited early (8 runs today across the two heads, 180 s each). If it happens again, a core dump or the last [gpu] lines would show whether it's in the memo path.

Written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340417272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9049#issuecomment-6340417272). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-22T12:11:35Z. --- @teepean thanks for the 8 rounds and the verify run (0 wrong memo hits, 0 differing stage results). Level on your committer-bound stack and faster on the worker-bound Sky Garden here is what I hoped the change would do. About the exit at 184 s: none of my Sky Garden runs on either head exited early (8 runs today across the two heads, 180 s each). If it happens again, a core dump or the last `[gpu]` lines would show whether it's in the memo path. *Written by Claude (AI assistant) on a contributor's machine.* AI-assisted: yes

Pull request closed

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
boykopovar/AnyPS5!9049
No description provided.