perf(libc): read private write watches per allocation without a region query #9098

Merged
EagleBearerYS merged 15 commits from upstream-pr/9098 into main 2026-10-27 01:57:17 +00:00
EagleBearerYS commented 2026-10-21 12:12:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T12:12:22Z.


What

On Windows, WindowsMappings::Collect walks a range of guest memory and collects the pages written since the last collect. For the guest arena's private allocations, each step asked VirtualQuery for the region before reading its write watch.

  • The cost in a large commit: Windows computes RegionSize by walking the rest of the region, so a collect deep in a large commit pays for the whole remainder. In one 449 MiB private commit, a query took 379.2 µs and the GetWriteWatch 2.2 µs.
  • The cost in pieces: a region also ends at every protection change. So each 16 KiB piece cost two system calls, and an allocation with several protections was read in several parts.

The change (this head replaces the earlier one; the first commit is fable-void's, under his name):

  1. perf(libc): read private write watches per allocation without a query (fable-void, from his 2760ad808).
    • The mappings keep the extent of every private allocation they make: added when a placeholder is replaced, erased on release.
    • A collect makes one GetWriteWatch per allocation from that map. A read can't span two allocations, so pieces committed one by one still take one read each, but the query per piece is gone.
    • The reported pages are unchanged.
  2. fix(libc): return false from a private collect over memory released behind the mappings.
    • When code that bypasses WindowsMappings releases memory inside a recorded extent, GetWriteWatch fails there.
    • A failed call now queries the region at the cursor. If it's no longer committed private memory, Collect returns false as before; otherwise the failure is still fatal.
  3. test(libc): check private collects against a region query under APS5_VERIFY_DIRECT_COLLECT.
    • The one case the map can't see: a page decommitted in place inside a recorded allocation by code that bypasses WindowsMappings. GetWriteWatch still succeeds over it there.
    • Nothing in the tree decommits that way today.
    • With the switch set, each collect also queries its span, and Collect throws, naming the span, if it succeeded over memory that's no longer committed private.
  4. perf(libc): count private collect calls only in the collect test. The call counters compile only where APS5_COUNT_MAPPING_QUERIES is set, as the address-space query counter does. The runtime's Collect updates no counter.

Linux and macOS are unchanged: WindowsMappings.hpp is Windows-only.

Measured on GitHub's Windows runner (a bench of Resident Evil Village (PPSA01556)'s traced load, 5,765 retired imports over 2,077 refreshes, on fork exp/rewatch-phases-fixed, not part of this PR; runs 39697304565 and 39697362432):

guest memory committed as main this PR's earlier head this head
one 449 MiB placeholder replacement 2,120-2,227 ms ~10 ms 10-12 ms
16 KiB placeholder replacements 130-135 ms 88-105 ms (88-97 beside the earlier head, 104-105 beside main), with no VirtualQuery

Resident Evil Village (PPSA01556) in-game: loading isn't faster.

  • Setup:
    • One four-arm session on Windows, an RTX 3070 Laptop GPU (NVIDIA 617.42), warm shader cache, APS5_LAZY_SHADER_PREPARE=1, APS5_NO_GPL=1, APS5_HOST_IMPORT_MIB=6400, and APS5_TRACE_SUMMARY_EVERY=1 for per-second summary lines, with no other profiling switch. GPU clocks weren't held.
    • The arms:
      • A = main 1ff5c8ac5c plus the #6457 fix (tree d56bdc5155);
      • B = A plus this PR's earlier head;
      • C = A plus this head's first three commits, without #9505;
      • D = A plus #9505.
  • The import mode decides the cost. Each run landed in one of two import modes, which can't be chosen: high, with about 130,000 MiB of imports made over the load, or low, about 14,000.
  • High mode: C cuts the queue worker's per-frame Driver.Packet.dispatch over the load (per-run table and sources):
    • A: 1,111 ms, in its one high-mode run;
    • B: 1,115 and 1,055 ms;
    • C: 569 ms, in its one high-mode run.
    • These are lower bounds. The per-second summaries list each interval's top 8 phases, and a missing phase counts as 0. Dispatch is missing in 75 of C's 333 intervals, against 5-11 in the other runs.
    • Setting each missing interval to its 8th phase gives the upper bounds (q3b_check.py, its output): C at most 956 ms, A 1,191, and B 1,190 and 1,191.
    • So C is lower than A and B either way, by 14-49 % against A.
  • Low mode: no arm separates (same table). The figures are A 681 ms (run A3), C 735 and D 800 and 732. A's other low-mode run, A2r, read 285 ms, but its load began from a menu-warmed state after a late Yes, so it's left out.
  • Launch to the first gameplay frame: no arm separates in either mode.
    • High: A 42:11, B 39:37 and 45:50, C 44:16.
    • Low: A 35:51 and 39:45, C 37:32, D 41:05 and 38:16.
    • So the cut in dispatch time doesn't shorten the load here, which is bound elsewhere.

A second session, B A A B (2026-10-24) (runs, table and script):

  • Setup: the same machine, driver, warm shader cache and environment as above, with GPU clocks not held. A is d56bdc5155 again. B is A plus this PR's earlier change (74dee0062c and its follow-up 156fa1f175).
  • Import mode: B, A and B ran in the low import mode. The second A ran in the high mode and isn't compared.
  • From Yes to the first lit frame: no measurable difference. B took 23:34 and 26:20; A took 27:46 in its one low-mode run. B's own runs are 2:46 apart.
  • Driver.Packet.dispatch per frame over the load (presents-weighted as above, with the window starting at Yes):
    • B 668 and 771 ms, A 827 ms. These are lower bounds: dispatch is missing from 11 of B's 334 intervals, 10 of its 336, and 9 of A's 404.
    • With each missing interval set to its 8th phase, the upper bounds are B 748 and 854 ms, A 904 ms.
    • B's second run overlaps A, and the first session's low-mode A read 681–736 ms, so the arms don't separate in low mode here either.

Overlap:

  • #9505: merged since. This head sits on #9505's fbf50df422 (its merge with main 0ea0f25e1b), whose shared-view change it composes with.
  • #9159: merged since. Its four test cases in core/libs/tests/WindowsWriteWatch.cpp came in through #9505's merge, and this PR's case runs beside them (see Tested).
  • main: merged in 98fd280383, through #9505's merge. main's #10070 moved the placeholder replacement in Commit into a replace helper and added a path that carves whole granules out of one placeholder. This PR's bookkeeping moved with it: replace records each private allocation, so allocations on either path are recorded, and the new path erases the records over the range it replaces, as reset does on the other path.

Tested

  • agc_private_collect (new, fable-void's): 256 MiB of 16 KiB pieces with scattered writes returns the same pages as a reference read, with at most one system call per piece. One allocation in five protection regions takes one call.
    • It fails without the first commit (32,768 calls for 16,384 pieces) and passes with it (16,384).
  • windows_write_watch: a collected private allocation released with VirtualFree behind the mappings must collect false without throwing. Without the second commit it throws.
  • windows_write_watch_verify_direct: under the switch, a collect after a page is decommitted in place must not succeed. Without the third commit's check it succeeds.
  • Reds and greens:
  • GitHub's runners on this head (run 39703221475):
    • Windows: 8 tests ×10, including agc_private_collect with the guarded counters, windows_shared_map_cost and both write-watch tests;
    • Linux: 4 tests ×10;
    • the libc and libkernel suites pass on both.
  • This head merged with main 7b32a842f8 (run 39890788684):
    • Windows: agc_private_collect, windows_shared_map_cost, windows_write_watch and windows_write_watch_verify_direct pass ×10. The 8 agc_import_* tests skip, because the runner has no Vulkan device;
    • Linux: agc_import_watch passes ×10;
    • the libc suite (144 on Windows, 117 on Linux) and the libkernel suite (208, 198) pass. They ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners;
    • with main's code, the Windows tests don't build, because they use the new calls.
  • 98fd280383, merged with #9505's merge of main 1e20650e84 (run), with the bookkeeping moved as described under Overlap:
    • Windows: agc_private_collect, windows_shared_map_cost, windows_write_watch, windows_write_watch_verify_direct, guest_memory, guest_shm_open and guest_jit_shared_memory pass ×10: 8 run, 7 pass, 1 skip, 0 fail. agc_import_watch skips, as the runner has no Vulkan device;
    • Linux: agc_import_watch, guest_memory, guest_shm_open and guest_jit_shared_memory pass ×10: 4 run, 4 pass, 0 skip, 0 fail;
    • the libc suite (147 on Windows, 120 on Linux) and the libkernel suite (213, 203) ran with APS5_SKIP_TIMING_TESTS=1. All pass except libkernel's guest_raise_in_system_call on Windows, which timed out after 30 s as the suite's 211th of 213. Run alone 20 times in a row, it and guest_raise_exception pass on this head (run) and on main 1e20650e84 (run), as #9505 records for its own head.
  • bc0971afbc, merged with #9505's merge of main 0ea0f25e1b (run). One conflict, the list of cases in WindowsWriteWatch.cpp's main(), where both sides are kept: this PR's CheckReleasedPrivateAllocation and #9159's four compared-shared cases. This PR's own added and removed lines are unchanged.
    • Windows: agc_private_collect, windows_shared_map_cost, windows_write_watch, windows_write_watch_verify_direct, #9159's agc_rewatched_direct_shared, agc_import_alias_shared and agc_compared_shared_generations, guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 12 run, 11 pass, 1 skip (agc_import_watch, no Vulkan device), 0 fail;
    • Linux: agc_import_watch, guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 5 run, 5 pass, 0 skip, 0 fail;
    • the libc and libkernel suites pass on both (170 and 221 tests on Windows, 143 and 205 on Linux), run with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • check_conventions.py: passes. No comment lines are added.
  • 1f691a369e, agc_private_collect_tests built in a plain build (run), after thuanquang's review: the target was added with EXCLUDE_FROM_ALL and nothing turned it back on, so a plain cmake --build build never built it, and a full ctest would report agc_private_collect as Not Run. The flag is dropped. On Windows, a plain build of all builds it, and the test passes 10 runs in a row: 1 run, 1 pass, 0 skip, 0 fail. Linux: 0 run, as the test is registered on Windows only. Suites: libc and libkernel pass on Windows (170 and 221). The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none; #9505 merged. Merge order with thuanquang's #11152 (overlapping lines in core/libs/prx/libc/include/WindowsMappings.hpp): this PR first, then #11152 rebases onto it
  • Fixes: none
  • Related: #8926
  • Unblocks: none. On Resident Evil Village (PPSA01556) it lowers the queue worker's per-frame dispatch time in the high import mode (one high-mode run each for A and C, two for B), but the load is no faster.
  • GPUs tested: none needed (CPU-side write tracking); Windows build and tests on GitHub's runner, plus the Village session on an RTX 3070 Laptop GPU
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951336789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9098). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T12:12:22Z. --- ### What On Windows, `WindowsMappings::Collect` walks a range of guest memory and collects the pages written since the last collect. For the guest arena's private allocations, each step asked `VirtualQuery` for the region before reading its write watch. - **The cost in a large commit:** Windows computes `RegionSize` by walking the rest of the region, so a collect deep in a large commit pays for the whole remainder. In one 449 MiB private commit, a query took 379.2 µs and the `GetWriteWatch` 2.2 µs. - **The cost in pieces:** a region also ends at every protection change. So each 16 KiB piece cost two system calls, and an allocation with several protections was read in several parts. **The change** (this head replaces the earlier one; the first commit is fable-void's, under his name): 1. **`perf(libc): read private write watches per allocation without a query`** (fable-void, from his 2760ad808). - The mappings keep the extent of every private allocation they make: added when a placeholder is replaced, erased on release. - A collect makes one `GetWriteWatch` per allocation from that map. A read can't span two allocations, so pieces committed one by one still take one read each, but the query per piece is gone. - The reported pages are unchanged. 2. **`fix(libc): return false from a private collect over memory released behind the mappings`.** - When code that bypasses `WindowsMappings` releases memory inside a recorded extent, `GetWriteWatch` fails there. - A failed call now queries the region at the cursor. If it's no longer committed private memory, `Collect` returns `false` as before; otherwise the failure is still fatal. 3. **`test(libc): check private collects against a region query under APS5_VERIFY_DIRECT_COLLECT`.** - **The one case the map can't see:** a page decommitted in place inside a recorded allocation by code that bypasses `WindowsMappings`. `GetWriteWatch` still succeeds over it there. - Nothing in the tree decommits that way today. - With the switch set, each collect also queries its span, and `Collect` throws, naming the span, if it succeeded over memory that's no longer committed private. 4. **`perf(libc): count private collect calls only in the collect test`.** The call counters compile only where `APS5_COUNT_MAPPING_QUERIES` is set, as the address-space query counter does. The runtime's `Collect` updates no counter. **Linux and macOS are unchanged:** `WindowsMappings.hpp` is Windows-only. **Measured on GitHub's Windows runner** (a bench of Resident Evil Village (PPSA01556)'s traced load, 5,765 retired imports over 2,077 refreshes, on fork `exp/rewatch-phases-fixed`, not part of this PR; runs [39697304565](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39697304565) and [39697362432](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39697362432)): | guest memory committed as | `main` | this PR's earlier head | this head | |---|---|---|---| | one 449 MiB placeholder replacement | 2,120-2,227 ms | ~10 ms | 10-12 ms | | 16 KiB placeholder replacements | | 130-135 ms | **88-105 ms** (88-97 beside the earlier head, 104-105 beside `main`), with no `VirtualQuery` | **Resident Evil Village (PPSA01556) in-game: loading isn't faster.** - **Setup:** - One four-arm session on Windows, an RTX 3070 Laptop GPU (NVIDIA 617.42), warm shader cache, `APS5_LAZY_SHADER_PREPARE=1`, `APS5_NO_GPL=1`, `APS5_HOST_IMPORT_MIB=6400`, and `APS5_TRACE_SUMMARY_EVERY=1` for per-second summary lines, with no other profiling switch. GPU clocks weren't held. - The arms: - A = `main` 1ff5c8ac5c plus the #6457 fix (tree d56bdc5155); - B = A plus this PR's earlier head; - C = A plus this head's first three commits, without #9505; - D = A plus #9505. - **The import mode decides the cost.** Each run landed in one of two import modes, which can't be chosen: high, with about 130,000 MiB of imports made over the load, or low, about 14,000. - **High mode:** C cuts the queue worker's per-frame `Driver.Packet.dispatch` over the load ([per-run table and sources](https://github.com/EagleBearerYS/AnyPS5/blob/f14ea32cfb/9098/README.md)): - A: 1,111 ms, in its one high-mode run; - B: 1,115 and 1,055 ms; - C: **569 ms**, in its one high-mode run. - **These are lower bounds.** The per-second summaries list each interval's top 8 phases, and a missing phase counts as 0. Dispatch is missing in 75 of C's 333 intervals, against 5-11 in the other runs. - Setting each missing interval to its 8th phase gives the upper bounds ([`q3b_check.py`](https://github.com/EagleBearerYS/AnyPS5/blob/f14ea32cfb/9098/q3b_check.py), [its output](https://github.com/EagleBearerYS/AnyPS5/blob/f14ea32cfb/9098/q3b_check-output.txt)): C at most 956 ms, A 1,191, and B 1,190 and 1,191. - So C is lower than A and B either way, by 14-49 % against A. - **Low mode:** no arm separates ([same table](https://github.com/EagleBearerYS/AnyPS5/blob/f14ea32cfb/9098/README.md)). The figures are A 681 ms (run A3), C 735 and D 800 and 732. A's other low-mode run, A2r, read 285 ms, but its load began from a menu-warmed state after a late Yes, so it's left out. - **Launch to the first gameplay frame:** no arm separates in either mode. - High: A 42:11, B 39:37 and 45:50, C 44:16. - Low: A 35:51 and 39:45, C 37:32, D 41:05 and 38:16. - So the cut in dispatch time doesn't shorten the load here, which is bound elsewhere. **A second session, B A A B (2026-10-24)** ([runs, table and script](https://github.com/EagleBearerYS/AnyPS5/blob/d3c916bfde/9098/README.md#second-session-b-a-a-b-load-runs-q9098-2026-10-24)): - **Setup:** the same machine, driver, warm shader cache and environment as above, with GPU clocks not held. A is d56bdc5155 again. B is A plus this PR's earlier change (74dee0062c and its follow-up 156fa1f175). - **Import mode:** B, A and B ran in the low import mode. The second A ran in the high mode and isn't compared. - **From Yes to the first lit frame:** no measurable difference. B took 23:34 and 26:20; A took 27:46 in its one low-mode run. B's own runs are 2:46 apart. - **`Driver.Packet.dispatch` per frame over the load** (presents-weighted as above, with the window starting at Yes): - B 668 and 771 ms, A 827 ms. These are lower bounds: dispatch is missing from 11 of B's 334 intervals, 10 of its 336, and 9 of A's 404. - With each missing interval set to its 8th phase, the upper bounds are B 748 and 854 ms, A 904 ms. - B's second run overlaps A, and the first session's low-mode A read 681–736 ms, so the arms don't separate in low mode here either. **Overlap:** - **#9505:** merged since. This head sits on #9505's fbf50df422 (its merge with `main` 0ea0f25e1b), whose shared-view change it composes with. - **#9159:** merged since. Its four test cases in `core/libs/tests/WindowsWriteWatch.cpp` came in through #9505's merge, and this PR's case runs beside them (see Tested). - **`main`:** merged in 98fd280383, through #9505's merge. `main`'s #10070 moved the placeholder replacement in `Commit` into a `replace` helper and added a path that carves whole granules out of one placeholder. This PR's bookkeeping moved with it: `replace` records each private allocation, so allocations on either path are recorded, and the new path erases the records over the range it replaces, as `reset` does on the other path. ### Tested - **`agc_private_collect`** (new, fable-void's): 256 MiB of 16 KiB pieces with scattered writes returns the same pages as a reference read, with at most one system call per piece. One allocation in five protection regions takes one call. - It fails without the first commit (32,768 calls for 16,384 pieces) and passes with it (16,384). - **`windows_write_watch`:** a collected private allocation released with `VirtualFree` behind the mappings must collect `false` without throwing. Without the second commit it throws. - **`windows_write_watch_verify_direct`:** under the switch, a collect after a page is decommitted in place must not succeed. Without the third commit's check it succeeds. - **Reds and greens:** - the second and third commits' red, with only their hunks reverted: 3/3 ([run 39700582279](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39700582279), [run 39700652709](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39700652709)); - green 10/10 ([run 39700706478](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39700706478)). - **GitHub's runners on this head** ([run 39703221475](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39703221475)): - Windows: 8 tests ×10, including `agc_private_collect` with the guarded counters, `windows_shared_map_cost` and both write-watch tests; - Linux: 4 tests ×10; - the libc and libkernel suites pass on both. - **This head merged with `main` 7b32a842f8** ([run 39890788684](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39890788684)): - Windows: `agc_private_collect`, `windows_shared_map_cost`, `windows_write_watch` and `windows_write_watch_verify_direct` pass ×10. The 8 `agc_import_*` tests skip, because the runner has no Vulkan device; - Linux: `agc_import_watch` passes ×10; - the libc suite (144 on Windows, 117 on Linux) and the libkernel suite (208, 198) pass. They ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners; - with `main`'s code, the Windows tests don't build, because they use the new calls. - **98fd280383, merged with #9505's merge of `main` 1e20650e84** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40073391977)), with the bookkeeping moved as described under Overlap: - Windows: `agc_private_collect`, `windows_shared_map_cost`, `windows_write_watch`, `windows_write_watch_verify_direct`, `guest_memory`, `guest_shm_open` and `guest_jit_shared_memory` pass ×10: 8 run, 7 pass, 1 skip, 0 fail. `agc_import_watch` skips, as the runner has no Vulkan device; - Linux: `agc_import_watch`, `guest_memory`, `guest_shm_open` and `guest_jit_shared_memory` pass ×10: 4 run, 4 pass, 0 skip, 0 fail; - the libc suite (147 on Windows, 120 on Linux) and the libkernel suite (213, 203) ran with `APS5_SKIP_TIMING_TESTS=1`. All pass except libkernel's `guest_raise_in_system_call` on Windows, which timed out after 30 s as the suite's 211th of 213. Run alone 20 times in a row, it and `guest_raise_exception` pass on this head ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40075387359)) and on `main` 1e20650e84 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40075061251)), as #9505 records for its own head. - **bc0971afbc, merged with #9505's merge of `main` 0ea0f25e1b** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40127487985)). One conflict, the list of cases in `WindowsWriteWatch.cpp`'s `main()`, where both sides are kept: this PR's `CheckReleasedPrivateAllocation` and #9159's four compared-shared cases. This PR's own added and removed lines are unchanged. - Windows: `agc_private_collect`, `windows_shared_map_cost`, `windows_write_watch`, `windows_write_watch_verify_direct`, #9159's `agc_rewatched_direct_shared`, `agc_import_alias_shared` and `agc_compared_shared_generations`, `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 12 run, 11 pass, 1 skip (`agc_import_watch`, no Vulkan device), 0 fail; - Linux: `agc_import_watch`, `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 5 run, 5 pass, 0 skip, 0 fail; - the libc and libkernel suites pass on both (170 and 221 tests on Windows, 143 and 205 on Linux), run with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **`check_conventions.py`:** passes. No comment lines are added. - **1f691a369e, `agc_private_collect_tests` built in a plain build** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40276556951)), after thuanquang's review: the target was added with `EXCLUDE_FROM_ALL` and nothing turned it back on, so a plain `cmake --build build` never built it, and a full ctest would report `agc_private_collect` as Not Run. The flag is dropped. On Windows, a plain build of `all` builds it, and the test passes 10 runs in a row: 1 run, 1 pass, 0 skip, 0 fail. Linux: 0 run, as the test is registered on Windows only. Suites: libc and libkernel pass on Windows (170 and 221). The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. ### 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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none; #9505 merged. Merge order with thuanquang's #11152 (overlapping lines in `core/libs/prx/libc/include/WindowsMappings.hpp`): this PR first, then #11152 rebases onto it - [x] Fixes: none - [x] Related: #8926 - [x] Unblocks: none. On Resident Evil Village (PPSA01556) it lowers the queue worker's per-frame dispatch time in the high import mode (one high-mode run each for A and C, two for B), but the load is no faster. - [x] GPUs tested: none needed (CPU-side write tracking); Windows build and tests on GitHub's runner, plus the Village session on an RTX 3070 Laptop GPU - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 12:12:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T12:12:40Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315606591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9098#issuecomment-6315606591). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T12:12:40Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
CnRJay commented 2026-10-21 17:42:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:42:52Z.

Review: COMMENTED


Good PR: the cost is isolated and measured (VirtualQuery 379.2 us of a 383.9 us collect inside one 449 MiB commit, because Windows walks the rest of the region), the direct path trusts only the proof Collect already relied on, and the safety argument lists every path that clears it. The large-commit result (2,221 ms to 28.5 ms for 5,765 spans) is clear.

  • The other row of its own table is a regression: 16 KiB placeholder replacements go from 171 ms to 197 ms (+15%), because each span now makes one failed GetWriteWatch call and then the old queries. A title whose arena is committed in many small pieces pays this on every collect. Remember the failure: keep the proof from being used for that allocation (or that range) until the arena's commit state changes, so the failed call happens once, not once per span.
  • The bench isn't part of the PR, and it measures Collect in isolation. The effect on a title is the thing that matters: Village's load with #8926's rewatch, load time or presents, main against this PR, from the same machine, without APS5_PROFILE_*. 2.2 s of collect time over the load is real, but a title measurement shows whether it's on the critical path.
  • "The one unguarded case: a page decommitted in place inside a still-proven write-watch allocation, by code that bypasses WindowsMappings. Nothing in the tree does that." Add a debug check that the direct call's result matches the old path's on a sample (or under a verify switch), so a later caller that does that is caught, rather than relying on nothing doing it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5603820332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9098#pullrequestreview-5603820332). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-21T17:42:52Z. **Review:** COMMENTED --- Good PR: the cost is isolated and measured (`VirtualQuery` 379.2 us of a 383.9 us collect inside one 449 MiB commit, because Windows walks the rest of the region), the direct path trusts only the proof `Collect` already relied on, and the safety argument lists every path that clears it. The large-commit result (2,221 ms to 28.5 ms for 5,765 spans) is clear. - The other row of its own table is a regression: 16 KiB placeholder replacements go from 171 ms to 197 ms (+15%), because each span now makes one failed `GetWriteWatch` call and then the old queries. A title whose arena is committed in many small pieces pays this on every collect. Remember the failure: keep the proof from being used for that allocation (or that range) until the arena's commit state changes, so the failed call happens once, not once per span. - The bench isn't part of the PR, and it measures `Collect` in isolation. The effect on a title is the thing that matters: Village's load with #8926's rewatch, load time or presents, main against this PR, from the same machine, without `APS5_PROFILE_*`. 2.2 s of collect time over the load is real, but a title measurement shows whether it's on the critical path. - "The one unguarded case: a page decommitted in place inside a still-proven write-watch allocation, by code that bypasses `WindowsMappings`. Nothing in the tree does that." Add a debug check that the direct call's result matches the old path's on a sample (or under a verify switch), so a later caller that does that is caught, rather than relying on nothing doing it.
EagleBearerYS commented 2026-10-21 17:47:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T17:47:54Z.


@CnRJay, thank you for the review.

We ran that title measurement on Resident Evil Village (PPSA01556): main 1ff5c8ac5c with #8926, against the same with this PR, on one machine, warm shader cache, no APS5_PROFILE_*, timed from Yes to the first gameplay frame, in the order B A A B:

  • without this PR: 16:42 and 11:31 (runs 2 and 3);
  • with this PR: 23:33 and 19:57 (runs 1 and 4).

It was slower in both runs, so we don't claim a load-time gain. That's two runs per arm, with a 5-minute spread between the two base runs, and GPU clocks weren't held. A traced minute of each load showed a ~16 s stall with two queue workers in Driver.Packet.memory_wait in this PR's run only, but the two windows fell ~50 s apart in their loads. We're profiling the collect path in the load before saying more.

We'll add both of your other points: remembering a failed GetWriteWatch for that allocation until the arena's commit state changes, and a verify switch that compares the direct call's result with the old path's.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322675900 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9098#issuecomment-6322675900). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T17:47:54Z. --- @CnRJay, thank you for the review. We ran that title measurement on Resident Evil Village (PPSA01556): `main` 1ff5c8ac5c with #8926, against the same with this PR, on one machine, warm shader cache, no `APS5_PROFILE_*`, timed from Yes to the first gameplay frame, in the order B A A B: - without this PR: 16:42 and 11:31 (runs 2 and 3); - with this PR: 23:33 and 19:57 (runs 1 and 4). It was slower in both runs, so we don't claim a load-time gain. That's two runs per arm, with a 5-minute spread between the two base runs, and GPU clocks weren't held. A traced minute of each load showed a ~16 s stall with two queue workers in `Driver.Packet.memory_wait` in this PR's run only, but the two windows fell ~50 s apart in their loads. We're profiling the collect path in the load before saying more. We'll add both of your other points: remembering a failed `GetWriteWatch` for that allocation until the arena's commit state changes, and a verify switch that compares the direct call's result with the old path's.
EagleBearerYS commented 2026-10-21 18:49:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T18:49:40Z.


@CnRJay, your first and third points are in:

  • 9e9afb9c74 remembers a failed direct call until the arena's commit state changes, so a span that crosses allocations pays it once, not on every collect.
  • 47e1497389 adds APS5_VERIFY_DIRECT_COLLECT, which checks each direct call against a region query and throws, naming the span, on a mismatch.

Each has its red with only its check reverted (run 39651317856, run 39651193432), and both pass ×10 on Windows (run 39648160729).

One correction and one finding:

  • The 16 KiB gap was mostly runner variance. The 171 against 197 ms in the description compared runs on different runners. In one run (run 39651246424), the 5,765 failed direct calls cost ~6 ms of GetWriteWatch time (118.8 ms with them, 112.9 without). With 9e9afb9c74 the collect makes the same calls as main's path, and took 217.8 ms in all, against 218.9 with the first commit alone. The description now has the same-run numbers.
  • The in-place decommit case is real. The new verify test shows that GetWriteWatch succeeds over a page decommitted in place inside a proven allocation, so the direct path would report no writes there where the old path returns false. Nothing in the tree decommits that way today, and the switch now catches it if a caller ever does.

Your second point, the Resident Evil Village (PPSA01556) load, follows after the profiled pair.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323898608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9098#issuecomment-6323898608). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T18:49:40Z. --- @CnRJay, your first and third points are in: - 9e9afb9c74 remembers a failed direct call until the arena's commit state changes, so a span that crosses allocations pays it once, not on every collect. - 47e1497389 adds `APS5_VERIFY_DIRECT_COLLECT`, which checks each direct call against a region query and throws, naming the span, on a mismatch. Each has its red with only its check reverted ([run 39651317856](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39651317856), [run 39651193432](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39651193432)), and both pass ×10 on Windows ([run 39648160729](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39648160729)). One correction and one finding: - **The 16 KiB gap was mostly runner variance.** The 171 against 197 ms in the description compared runs on different runners. In one run ([run 39651246424](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39651246424)), the 5,765 failed direct calls cost ~6 ms of `GetWriteWatch` time (118.8 ms with them, 112.9 without). With 9e9afb9c74 the collect makes the same calls as `main`'s path, and took 217.8 ms in all, against 218.9 with the first commit alone. The description now has the same-run numbers. - **The in-place decommit case is real.** The new verify test shows that `GetWriteWatch` succeeds over a page decommitted in place inside a proven allocation, so the direct path would report no writes there where the old path returns `false`. Nothing in the tree decommits that way today, and the switch now catches it if a caller ever does. Your second point, the Resident Evil Village (PPSA01556) load, follows after the profiled pair.
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!9098
No description provided.