perf(agc): cache freed small blocks per thread on Windows #6650

Merged
WallisSkill merged 1 commit from upstream-pr/6650 into main 2026-10-19 08:34:43 +00:00
WallisSkill commented 2026-10-16 01:49:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by WallisSkill on 2026-10-16T01:49:58Z.


What

Split out of #5892 as CnRJay asked there.

perf(agc): cache freed small blocks per thread on Windows. Recording draws allocates and frees many small objects (shared_ptr control blocks, vectors, keys). In Cat Quest III's overworld RtlAllocateHeap/RtlFreeHeap took about a fifth of the queue worker's time (APS5_SAMPLE_WORKER, measured on an older base before #5892; the table below is on current main). The driver's operator new/delete now keep up to 64 freed blocks per 16-byte size class (up to 1 KiB) per thread. Larger requests go straight to malloc/free.

The review asked about two cases:

  • Blocks that cross module boundaries.
    • Every block handed out or cached is an ordinary UCRT malloc block, the same heap libstdc++'s operator new uses. The driver imports malloc, free and _msize from api-ms-win-crt-heap and nothing heap-related from libc.prx, so a block allocated here and freed by libstdc++ (or the other way round) is still a matching malloc and free.
    • A freed block is filed under the size class its _msize can hold, never under the size the caller asked for. The only exception is a sized delete whose size is a whole number of 16-byte granules: there _msize equals the size, whoever allocated the block.
    • The operators are excluded from the driver's automatic exports (--exclude-symbols), so other libraries (libSceAgc, libSceVideoOut) keep binding to libstdc++'s operators. Without that they bound to the driver's through the import library, and the NID patcher renamed them.
  • Thread exit.
    • A thread's cache hangs off a fiber-local-storage slot whose callback runs when the thread ends. The callback marks the thread's TLS slot closed, frees every cached block and then the cache itself.
    • Deletes that run later in that thread's teardown see the closed slot and go straight to free.
    • A block cached by one thread can be freed into another thread's cache; both are plain malloc blocks.

The cache is reached through a native TLS slot (read from the TEB for the first 64 slots), not thread_local. MinGW emulates thread_local through __emutls_get_address → pthread_getspecific, which cost more per call than the heap work it saved (about 16% of the worker). For the same reason, PageStates::initialize checks an atomic flag before std::call_once, whose callable also goes through emulated TLS.

New test agc_driver_host_allocator (Windows). It builds the allocator into a test executable linked to the shared libstdc++ and covers:

  • every size from 1 to 2048 bytes;
  • sized deletes in every class;
  • strings that libstdc++ grows and that std::getline (compiled into libstdc++) reallocates;
  • blocks allocated on one thread and freed on another;
  • 256 threads that end with cached blocks.

Tested

Windows 11 Pro 26200, MinGW GCC 15.2.0, NVIDIA GeForce RTX 5070 (driver 616.92), current main (ab9a47684) + this commit.

  • agc_driver_host_allocator: passes 10 of 10 repeated runs.

  • Cat Quest III (PPSA15065): overworld, standing still after loading the save, APS5_TRACE_SECONDS=240:20, warm caches, one build, same scene in both runs. A local-only switch (APS5_DBG_NO_ALLOC_CACHE, not in this PR) makes operator new/delete go straight to malloc/free.

    frame p50 / p90 / p99 ms presents in 20 s queue worker busy
    cache off (main behaviour) 9.5 / 11.0 / 13.3 2073 98.7 %
    this commit 8.3 / 8.7 / 10.0 2392 96.9 %

    With the cache the title sits at its 120 FPS cap (2392 presents in 20 s), so the frame times are an upper bound for this commit. e6c30f265d04 is this commit on ab9a47684 plus the local switch.

    Summary lines (APS5_PAD_INPUT_FILE removed):

    {"commit":"e6c30f265d04","dirty":false,"env":{"APS5_AUDIO_LATENCY_MS":"100","APS5_DBG_NO_ALLOC_CACHE":"1","APS5_TRACE_SECONDS":"240:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"1920x1080","window":{"spec":"seconds 240:20","first_present":26409,"ms":20005.591},"presents":2073,"frame_ms":{"p50":9.471,"p90":11.017,"p99":13.258,"max":20.25},"gpu_busy_ms_per_present":2.23,"worker_busy_pct":{"queue worker 0x0":98.727},"top_phases_ms_per_frame":{"Driver.Packet":9.24,"Driver.Packet.draw":8.55,"Driver.Draw":8.502,"Driver.Draw.draw_and_resource_release":5.303,"Graphics.Draw":5.148,"Graphics.Draw.draw_and_resource_release":4.428,"Driver.Draw.shader_compile_and_link":1.999,"Shader.DrawStage":1.082},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":2.855,"events_lost":1593879,"totals_full":false}},"trace":"aps5-trace-e6c30f265d04-41348.json.gz"}
    {"commit":"e6c30f265d04","dirty":false,"env":{"APS5_AUDIO_LATENCY_MS":"100","APS5_TRACE_SECONDS":"240:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"1920x1080","window":{"spec":"seconds 240:20","first_present":28051,"ms":20001.939},"presents":2392,"frame_ms":{"p50":8.288,"p90":8.738,"p99":9.989,"max":11.837},"gpu_busy_ms_per_present":2.202,"worker_busy_pct":{"queue worker 0x0":96.945},"top_phases_ms_per_frame":{"Driver.Packet":8.026,"Driver.Packet.draw":7.351,"Driver.Draw":7.304,"Driver.Draw.draw_and_resource_release":4.532,"Graphics.Draw":4.4,"Graphics.Draw.draw_and_resource_release":3.841,"Driver.Draw.shader_compile_and_link":1.608,"Shader.DrawStage":0.889},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":2.911,"events_lost":1548316,"totals_full":false}},"trace":"aps5-trace-e6c30f265d04-43232.json.gz"}
    

    The traces (aps5-trace-e6c30f265d04-41348, -43232) are attached in a comment.

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
  • Unblocks: none (frame rate in PPSA15065 #5888; not a stop)
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 616.92, Windows 11 26200 (the test above and the title)
  • AI-assisted: yes (Claude Code); I reviewed and tested every change

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4882254713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650). Originally posted by [WallisSkill](https://github.com/WallisSkill) on 2026-10-16T01:49:58Z. --- ### What Split out of #5892 as CnRJay asked there. **`perf(agc)`: cache freed small blocks per thread on Windows.** Recording draws allocates and frees many small objects (`shared_ptr` control blocks, vectors, keys). In Cat Quest III's overworld `RtlAllocateHeap`/`RtlFreeHeap` took about a fifth of the queue worker's time (`APS5_SAMPLE_WORKER`, measured on an older base before #5892; the table below is on current `main`). The driver's `operator new`/`delete` now keep up to 64 freed blocks per 16-byte size class (up to 1 KiB) per thread. Larger requests go straight to `malloc`/`free`. The review asked about two cases: - **Blocks that cross module boundaries.** - Every block handed out or cached is an ordinary UCRT `malloc` block, the same heap libstdc++'s `operator new` uses. The driver imports `malloc`, `free` and `_msize` from `api-ms-win-crt-heap` and nothing heap-related from `libc.prx`, so a block allocated here and freed by libstdc++ (or the other way round) is still a matching `malloc` and `free`. - A freed block is filed under the size class its `_msize` can hold, never under the size the caller asked for. The only exception is a sized delete whose size is a whole number of 16-byte granules: there `_msize` equals the size, whoever allocated the block. - The operators are excluded from the driver's automatic exports (`--exclude-symbols`), so other libraries (`libSceAgc`, `libSceVideoOut`) keep binding to libstdc++'s operators. Without that they bound to the driver's through the import library, and the NID patcher renamed them. - **Thread exit.** - A thread's cache hangs off a fiber-local-storage slot whose callback runs when the thread ends. The callback marks the thread's TLS slot closed, frees every cached block and then the cache itself. - Deletes that run later in that thread's teardown see the closed slot and go straight to `free`. - A block cached by one thread can be freed into another thread's cache; both are plain `malloc` blocks. The cache is reached through a native TLS slot (read from the TEB for the first 64 slots), not `thread_local`. MinGW emulates `thread_local` through `__emutls_get_address` → `pthread_getspecific`, which cost more per call than the heap work it saved (about 16% of the worker). For the same reason, `PageStates::initialize` checks an atomic flag before `std::call_once`, whose callable also goes through emulated TLS. New test `agc_driver_host_allocator` (Windows). It builds the allocator into a test executable linked to the shared libstdc++ and covers: - every size from 1 to 2048 bytes; - sized deletes in every class; - strings that libstdc++ grows and that `std::getline` (compiled into libstdc++) reallocates; - blocks allocated on one thread and freed on another; - 256 threads that end with cached blocks. ### Tested Windows 11 Pro 26200, MinGW GCC 15.2.0, NVIDIA GeForce RTX 5070 (driver 616.92), current `main` (ab9a47684) + this commit. - `agc_driver_host_allocator`: passes 10 of 10 repeated runs. - **Cat Quest III (PPSA15065):** overworld, standing still after loading the save, `APS5_TRACE_SECONDS=240:20`, warm caches, one build, same scene in both runs. A local-only switch (`APS5_DBG_NO_ALLOC_CACHE`, not in this PR) makes `operator new`/`delete` go straight to `malloc`/`free`. | | frame p50 / p90 / p99 ms | presents in 20 s | queue worker busy | |---|---|---|---| | cache off (`main` behaviour) | 9.5 / 11.0 / 13.3 | 2073 | 98.7 % | | this commit | 8.3 / 8.7 / 10.0 | 2392 | 96.9 % | With the cache the title sits at its 120 FPS cap (2392 presents in 20 s), so the frame times are an upper bound for this commit. `e6c30f265d04` is this commit on `ab9a47684` plus the local switch. Summary lines (`APS5_PAD_INPUT_FILE` removed): ```json {"commit":"e6c30f265d04","dirty":false,"env":{"APS5_AUDIO_LATENCY_MS":"100","APS5_DBG_NO_ALLOC_CACHE":"1","APS5_TRACE_SECONDS":"240:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"1920x1080","window":{"spec":"seconds 240:20","first_present":26409,"ms":20005.591},"presents":2073,"frame_ms":{"p50":9.471,"p90":11.017,"p99":13.258,"max":20.25},"gpu_busy_ms_per_present":2.23,"worker_busy_pct":{"queue worker 0x0":98.727},"top_phases_ms_per_frame":{"Driver.Packet":9.24,"Driver.Packet.draw":8.55,"Driver.Draw":8.502,"Driver.Draw.draw_and_resource_release":5.303,"Graphics.Draw":5.148,"Graphics.Draw.draw_and_resource_release":4.428,"Driver.Draw.shader_compile_and_link":1.999,"Shader.DrawStage":1.082},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":2.855,"events_lost":1593879,"totals_full":false}},"trace":"aps5-trace-e6c30f265d04-41348.json.gz"} {"commit":"e6c30f265d04","dirty":false,"env":{"APS5_AUDIO_LATENCY_MS":"100","APS5_TRACE_SECONDS":"240:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"1920x1080","window":{"spec":"seconds 240:20","first_present":28051,"ms":20001.939},"presents":2392,"frame_ms":{"p50":8.288,"p90":8.738,"p99":9.989,"max":11.837},"gpu_busy_ms_per_present":2.202,"worker_busy_pct":{"queue worker 0x0":96.945},"top_phases_ms_per_frame":{"Driver.Packet":8.026,"Driver.Packet.draw":7.351,"Driver.Draw":7.304,"Driver.Draw.draw_and_resource_release":4.532,"Graphics.Draw":4.4,"Graphics.Draw.draw_and_resource_release":3.841,"Driver.Draw.shader_compile_and_link":1.608,"Shader.DrawStage":0.889},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":2.911,"events_lost":1548316,"totals_full":false}},"trace":"aps5-trace-e6c30f265d04-43232.json.gz"} ``` The traces (`aps5-trace-e6c30f265d04-41348`, `-43232`) are attached in a comment. ### Checklist - [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] Unblocks: none (frame rate in PPSA15065 #5888; not a stop) - [x] GPUs tested: NVIDIA GeForce RTX 5070, driver 616.92, Windows 11 26200 (the test above and the title) - [x] AI-assisted: yes (Claude Code); I reviewed and tested every change 🤖 Generated with [Claude Code](https://claude.com/claude-code)
WallisSkill commented 2026-10-16 01:51:02 +00:00 (Migrated from github.com)
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206212640 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6206212640). Originally posted by [WallisSkill](https://github.com/WallisSkill) on 2026-10-16T01:51:02Z. --- [aps5-trace-e6c30f265d04-41348.json.gz](https://github.com/user-attachments/files/33520976/aps5-trace-e6c30f265d04-41348.json.gz) [aps5-trace-e6c30f265d04-43232.json.gz](https://github.com/user-attachments/files/33520978/aps5-trace-e6c30f265d04-43232.json.gz)
github-actions[bot] commented 2026-10-16 02:38:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T02:38:34Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1341 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 4448 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5426 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5480 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5499 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5656 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6044 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6146 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6185 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6249 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6292 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6479 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6501 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6611 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6615 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6683 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6701 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6730 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6747 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6763 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6788 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6868 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6887 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6937 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6941 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6946 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6947 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6960 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6963 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6965 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6973 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6987 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6989 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6995 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7002 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7048 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7085 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7201 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7223 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7233 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7310 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7332 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7432 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7505 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7514 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7604 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7615 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7627 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7647 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7800 core/libs/prx/libSceAgcDriver/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206798201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6206798201). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T02:38:34Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1341](https://www.github.com/boykopovar/AnyPS5/pull/1341) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 2434](https://www.github.com/boykopovar/AnyPS5/pull/2434) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 4448](https://www.github.com/boykopovar/AnyPS5/pull/4448) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 5426](https://www.github.com/boykopovar/AnyPS5/pull/5426) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 5480](https://www.github.com/boykopovar/AnyPS5/pull/5480) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 5656](https://www.github.com/boykopovar/AnyPS5/pull/5656) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6146](https://www.github.com/boykopovar/AnyPS5/pull/6146) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6185](https://www.github.com/boykopovar/AnyPS5/pull/6185) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6186](https://www.github.com/boykopovar/AnyPS5/pull/6186) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6192](https://www.github.com/boykopovar/AnyPS5/pull/6192) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6249](https://www.github.com/boykopovar/AnyPS5/pull/6249) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6300](https://www.github.com/boykopovar/AnyPS5/pull/6300) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6457](https://www.github.com/boykopovar/AnyPS5/pull/6457) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6479](https://www.github.com/boykopovar/AnyPS5/pull/6479) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6501](https://www.github.com/boykopovar/AnyPS5/pull/6501) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6611](https://www.github.com/boykopovar/AnyPS5/pull/6611) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6683](https://www.github.com/boykopovar/AnyPS5/pull/6683) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6701](https://www.github.com/boykopovar/AnyPS5/pull/6701) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6730](https://www.github.com/boykopovar/AnyPS5/pull/6730) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6747](https://www.github.com/boykopovar/AnyPS5/pull/6747) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6763](https://www.github.com/boykopovar/AnyPS5/pull/6763) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6788](https://www.github.com/boykopovar/AnyPS5/pull/6788) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6868](https://www.github.com/boykopovar/AnyPS5/pull/6868) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6887](https://www.github.com/boykopovar/AnyPS5/pull/6887) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6937](https://www.github.com/boykopovar/AnyPS5/pull/6937) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6941](https://www.github.com/boykopovar/AnyPS5/pull/6941) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6960](https://www.github.com/boykopovar/AnyPS5/pull/6960) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6963](https://www.github.com/boykopovar/AnyPS5/pull/6963) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6965](https://www.github.com/boykopovar/AnyPS5/pull/6965) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6973](https://www.github.com/boykopovar/AnyPS5/pull/6973) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6987](https://www.github.com/boykopovar/AnyPS5/pull/6987) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6989](https://www.github.com/boykopovar/AnyPS5/pull/6989) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 6995](https://www.github.com/boykopovar/AnyPS5/pull/6995) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7002](https://www.github.com/boykopovar/AnyPS5/pull/7002) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7048](https://www.github.com/boykopovar/AnyPS5/pull/7048) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7085](https://www.github.com/boykopovar/AnyPS5/pull/7085) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7223](https://www.github.com/boykopovar/AnyPS5/pull/7223) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7233](https://www.github.com/boykopovar/AnyPS5/pull/7233) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7310](https://www.github.com/boykopovar/AnyPS5/pull/7310) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7395](https://www.github.com/boykopovar/AnyPS5/pull/7395) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7432](https://www.github.com/boykopovar/AnyPS5/pull/7432) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7505](https://www.github.com/boykopovar/AnyPS5/pull/7505) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7514](https://www.github.com/boykopovar/AnyPS5/pull/7514) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7604](https://www.github.com/boykopovar/AnyPS5/pull/7604) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7615](https://www.github.com/boykopovar/AnyPS5/pull/7615) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7627](https://www.github.com/boykopovar/AnyPS5/pull/7627) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7647](https://www.github.com/boykopovar/AnyPS5/pull/7647) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` | | [PR 7800](https://www.github.com/boykopovar/AnyPS5/pull/7800) | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` |
simonbronk commented 2026-10-16 13:52:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-16T13:52:42Z.


Independent Windows CPU validation of d2d43e4dbc63d6ea5ba50d864a88094f2350587a (AI-assisted, OpenAI Codex).

Compiled the complete unchanged Execution/src/HostAllocator.cpp and the author's unchanged tests/HostAllocator.cpp with WinLibs GCC 15.2.0 r7 UCRT, -std=c++20 -O3 -DNDEBUG -pthread, dynamically linked libstdc++, no LTO. All four original-test executions pass (Host allocator tests passed, empty stderr).

A separate probe is linked either to the normal toolchain allocator or to this exact PR allocator. Each version runs four times in alternating order. It checks usable size/alignment and endpoint bytes during allocation batches, and all bytes in eight waves of 1,024 blocks allocated on one thread and freed on another. Every run has zero failures and the same checksum. This tests the allocator source, not the PageStates::initialize change or the whole driver's DLL integration.

Median of four process-batch means, ns per allocation/free pair (including _msize, alignment checks, memset and endpoint checks):

Workload, unsized delete Normal allocator PR allocator
One 64-byte block at a time, 300,000 pairs 65.31 28.10
Batches of 32, sizes 16..256 bytes, 320,000 pairs 83.79 37.50
Batches of 128, sizes 16..1,024 bytes, 1,280,000 pairs 743.04 41.41

The last case is a cache-warmed synthetic workload with unusually expensive normal-heap batches on this machine; it must not be read as a whole-draw or whole-game speedup. No affinity, priority, timer-resolution or power-policy changes. No representative allocation lifetime distribution or memory-footprint comparison.

An additional white-box probe includes the unchanged allocator file, reserves 96 Windows TLS slots before initialization, and observes allocator slot 99. It performs 1,000 reuse rounds through the expanded TLS path; usable sizes, exact pointer reuse and GetLastError preservation pass. This covers the TlsGetValue branch in addition to the default path; it is not an allocation-failure or fiber-lifecycle test.

Limits: standalone CPU tests only; no full native build, CTest, actual driver DLL export/import or unload checks, PageStates integration, race/failure injection, memory-leak proof, GPU/title/FPS or other-OS validation. Thread exits in the author's test complete successfully; this alone does not establish that every cached block was freed. Your title results remain your evidence.

Reproducer and raw results are attached below. Set CXX/toolchain path in run.py for another checkout location, then run it with Python; expanded.cpp is the separate white-box test. Source snapshots are pinned to the head above. No source change or duplicate PR from me.
windows-allocator-pr6650.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6217002978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6217002978). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-16T13:52:42Z. --- Independent Windows CPU validation of `d2d43e4dbc63d6ea5ba50d864a88094f2350587a` (AI-assisted, OpenAI Codex). Compiled the complete unchanged `Execution/src/HostAllocator.cpp` and the author's unchanged `tests/HostAllocator.cpp` with WinLibs GCC 15.2.0 r7 UCRT, `-std=c++20 -O3 -DNDEBUG -pthread`, dynamically linked libstdc++, no LTO. All four original-test executions pass (`Host allocator tests passed`, empty stderr). A separate probe is linked either to the normal toolchain allocator or to this exact PR allocator. Each version runs four times in alternating order. It checks usable size/alignment and endpoint bytes during allocation batches, and all bytes in eight waves of 1,024 blocks allocated on one thread and freed on another. Every run has zero failures and the same checksum. This tests the allocator source, not the `PageStates::initialize` change or the whole driver's DLL integration. Median of four process-batch means, **ns per allocation/free pair** (including `_msize`, alignment checks, memset and endpoint checks): | Workload, unsized delete | Normal allocator | PR allocator | |---|---:|---:| | One 64-byte block at a time, 300,000 pairs | 65.31 | 28.10 | | Batches of 32, sizes 16..256 bytes, 320,000 pairs | 83.79 | 37.50 | | Batches of 128, sizes 16..1,024 bytes, 1,280,000 pairs | 743.04 | 41.41 | The last case is a cache-warmed synthetic workload with unusually expensive normal-heap batches on this machine; it must not be read as a whole-draw or whole-game speedup. No affinity, priority, timer-resolution or power-policy changes. No representative allocation lifetime distribution or memory-footprint comparison. An additional white-box probe includes the unchanged allocator file, reserves 96 Windows TLS slots before initialization, and observes allocator slot 99. It performs 1,000 reuse rounds through the expanded TLS path; usable sizes, exact pointer reuse and `GetLastError` preservation pass. This covers the `TlsGetValue` branch in addition to the default path; it is not an allocation-failure or fiber-lifecycle test. Limits: standalone CPU tests only; no full native build, CTest, actual driver DLL export/import or unload checks, `PageStates` integration, race/failure injection, memory-leak proof, GPU/title/FPS or other-OS validation. Thread exits in the author's test complete successfully; this alone does not establish that every cached block was freed. Your title results remain your evidence. Reproducer and raw results are attached below. Set `CXX`/toolchain path in `run.py` for another checkout location, then run it with Python; `expanded.cpp` is the separate white-box test. Source snapshots are pinned to the head above. No source change or duplicate PR from me. [windows-allocator-pr6650.zip](https://github.com/user-attachments/files/33549085/windows-allocator-pr6650.zip)
WallisSkill commented 2026-10-16 18:52:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by WallisSkill on 2026-10-16T18:52:03Z.


@simonbronk thank you for the independent run, and for covering the TlsGetValue path above 64 slots, which my test did not reach.

On the limit you named (that thread exits passing does not show every cached block is freed), I pushed fc25ed9a7, which adds a leak check to agc_driver_host_allocator:

  • After 8 waves of 32 threads that end with full caches, it records the process's private bytes.
  • It runs 16 more waves and requires the growth to stay under 128 MiB.

Results here, 10 runs each, standalone builds of the same test (WinLibs GCC 15.2.0):

allocator growth over the last 16 waves test
toolchain default (no HostAllocator.cpp) -54 to +54 MiB passes
this PR -3 to +54 MiB passes 10 of 10
this PR with the drain in the thread-exit callback removed +362 to +375 MiB fails 10 of 10

The occasional ~52 MiB step shows up with the default allocator too: it is the heap growing once, not the cache. With the repository's build (DWARF unwinding, linked to libc), the test passes 10 of 10 under ctest --repeat until-fail:10.

On the overlap check above, I compared by hand every PR it could not compare:

  • GuestMemory.cpp: none of them changes PageStates or the lines this PR touches (hunks at 418, 477 and 501, around PageStates::initialize).
  • CMakeLists.txt: none touches the HostAllocator.cpp source line or the --exclude-symbols option. The only nearby change is #6044, which moves test registration to add_library_test(...); if it lands first I will register agc_driver_host_allocator the same way.
  • #1896, #4448, #6320, #6454 and #6481 call the aligned operator new/delete (std::align_val_t) in driver code. This PR replaces only the unaligned forms, so the aligned calls stay libstdc++'s on both sides and their pairs remain matched.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222503566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6222503566). Originally posted by [WallisSkill](https://github.com/WallisSkill) on 2026-10-16T18:52:03Z. --- @simonbronk thank you for the independent run, and for covering the `TlsGetValue` path above 64 slots, which my test did not reach. On the limit you named (that thread exits passing does not show every cached block is freed), I pushed fc25ed9a7, which adds a leak check to `agc_driver_host_allocator`: - After 8 waves of 32 threads that end with full caches, it records the process's private bytes. - It runs 16 more waves and requires the growth to stay under 128 MiB. Results here, 10 runs each, standalone builds of the same test (WinLibs GCC 15.2.0): | allocator | growth over the last 16 waves | test | |---|---|---| | toolchain default (no `HostAllocator.cpp`) | -54 to +54 MiB | passes | | this PR | -3 to +54 MiB | passes 10 of 10 | | this PR with the drain in the thread-exit callback removed | +362 to +375 MiB | fails 10 of 10 | The occasional ~52 MiB step shows up with the default allocator too: it is the heap growing once, not the cache. With the repository's build (DWARF unwinding, linked to `libc`), the test passes 10 of 10 under `ctest --repeat until-fail:10`. On the overlap check above, I compared by hand every PR it could not compare: - `GuestMemory.cpp`: none of them changes `PageStates` or the lines this PR touches (hunks at 418, 477 and 501, around `PageStates::initialize`). - `CMakeLists.txt`: none touches the `HostAllocator.cpp` source line or the `--exclude-symbols` option. The only nearby change is #6044, which moves test registration to `add_library_test(...)`; if it lands first I will register `agc_driver_host_allocator` the same way. - #1896, #4448, #6320, #6454 and #6481 call the aligned `operator new`/`delete` (`std::align_val_t`) in driver code. This PR replaces only the unaligned forms, so the aligned calls stay libstdc++'s on both sides and their pairs remain matched.
parl0v commented 2026-10-16 19:03:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T19:03:14Z.


Data point from a CPU-bound scene: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1; main 93e54cedd vs main + this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10 [present] windows, GPU busy and idle gaps per frame over the last 8.

libs FPS GPU busy idle gaps
main 6.61 / 6.61 104 / 105 ms 46 / 46 ms
+ this PR (d2d43e4db) 6.69 / 6.70 (+1.3 %) 105 / 107 ms 45 / 43 ms

Small but it repeated in both rounds, and main was flat (6.61 / 6.61). 0 fatal. Head d2d43e4db, before your leak-check commit.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222691209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6222691209). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T19:03:14Z. --- Data point from a CPU-bound scene: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, `APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1`; `main` 93e54cedd vs `main` + this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10 `[present]` windows, GPU busy and idle gaps per frame over the last 8. | libs | FPS | GPU busy | idle gaps | |---|---|---|---| | `main` | 6.61 / 6.61 | 104 / 105 ms | 46 / 46 ms | | + this PR (d2d43e4db) | 6.69 / 6.70 (**+1.3 %**) | 105 / 107 ms | 45 / 43 ms | Small but it repeated in both rounds, and `main` was flat (6.61 / 6.61). 0 fatal. Head d2d43e4db, before your leak-check commit. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-19 08:35:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:35:01Z.


Checked the allocator against the diff: every block stays a UCRT malloc block (size class taken from _msize, sized delete trusted only for whole 16-byte granules), the operators are kept out of the driver's exports so other libraries keep libstdc++'s, thread exit closes the TLS slot and drains the cache through the FLS callback, and the atomic fast path in PageStates::initialize is sound. The test is registered in ctest and exercises the real source, including the leak check. Independent runs by @simonbronk and @parl0v back the numbers. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263112643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6650#issuecomment-6263112643). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:35:01Z. --- Checked the allocator against the diff: every block stays a UCRT `malloc` block (size class taken from `_msize`, sized delete trusted only for whole 16-byte granules), the operators are kept out of the driver's exports so other libraries keep libstdc++'s, thread exit closes the TLS slot and drains the cache through the FLS callback, and the atomic fast path in `PageStates::initialize` is sound. The test is registered in ctest and exercises the real source, including the leak check. Independent runs by @simonbronk and @parl0v back the numbers. Merged.
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!6650
No description provided.