perf(memory): skip 4 MiB runs no write stamped since a range check #6266

Merged
meh7an merged 1 commit from upstream-pr/6266 into main 2026-10-18 21:27:15 +00:00
meh7an commented 2026-10-15 08:29:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-15T08:29:14Z.


What

GuestMemory::UnchangedSince and UnchangedSinceAll answer whether any 64 KiB block of a range was stamped after a generation. #1310 made that a tight scan of the block stamps, but the scan still reads every block of the range. Render targets are checked this way on every draw (StorageTexture::refreshProved, from refreshResidentTarget), and a 4K surface spans hundreds of blocks.

The write tracker now also keeps the newest stamp of each run of 64 blocks (4 MiB), and stamp raises it with the block's stamp. unchanged skips a whole run whose newest stamp is not after the generation. It scans the other runs, and the partial runs at either end, block by block as before.

  • Only initialize and stamp write block stamps, so a run's stamp cannot fall behind its blocks.
  • On Linux a run never crosses a leaf, because 64 divides LeafBlocks.

On the S2 page of Sonic Origins Plus's main menu, UnchangedSince cost the queue worker (APS5 sampler, 15 s):

  • before, in two runs: 62 and 86 samples, of which 47 and 60 were its own scan;
  • with this change: 50 samples, of which 31 were its own scan.

Per frame that is 0.76 to 0.44 samples. That is about 0.6% of the worker's frame, so the frame times below move within run-to-run noise.

Tested

Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.

  • On main db81992c5 with this change, the full ctest suite passes: 1253 of 1254 tests. The other one, agc_driver_draw_program_trace, is not run, because its test executable does not link under MinGW on main itself (__gxx_personality_v0 is undefined); it does not contain the code changed here.
    • agc_write_tracking has a new check, CheckCoarseRuns, over a range of 192 blocks. A driver store inside whole runs and a CPU store into the last block must both be seen, and blocks outside the stored one must stay unchanged.
    • The check fails ("a driver store inside whole 4 MiB runs of the range is not seen") when stamp leaves the run stamp alone.
  • Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window.
    • Captured with APS5_TRACE_SECONDS=200:15 on the same machine in one session, caches warm. Traces attached.
    • Baseline b593e36eccba, this change b8acbb0d6 (its summary says a38ad5e9fc89, see the note):
Metric Baseline This PR Change
frame_ms.p50 130.365 130.139 -0.2%
frame_ms.p90 136.606 132.568 -3.0%
mean_frame_ms 133.147 130.258 -2.2%
gpu_busy_ms_per_present 83.817 85.039 +1.5%
Driver.Packet (ms per frame) 130.567 127.684 -2.2%

The median frame did not move. The mean and p90 differences come mostly from a few slow frames in the baseline's window (p99 160.8 against 135.1 ms), which is run-to-run noise at this size.

The FPS shown in the title went from 7.91 to 8.34 (median of six readings). The sampled pair, run an hour earlier, showed 7.55 and 7.51, so neither pair moves beyond run-to-run noise.

Note: measuring base. These numbers come from my fork's dev, on main 0a56aaaf4, the last main before #5596. On Windows, later mains compare direct imports on every use, which keeps this menu at 3-4 FPS and hides a change of this size.

Both carry these commits from my fork:

  • the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373 and 10ff693aa (#5778);
  • make-exe and the stage dumps (522230d62, deee71fde);
  • the crash-report sampler (8d9c3103e..f641e1ec9), which took the profiles;
  • #6037, #6066, #6077, #6067, #6082 (its first version, before #5906) and #6095;
  • seven smaller steps kept in my fork: e83260247, 97b1ff6c9, 84f5bf0ff, 52704cf7c (covered on main by #5062), c0c3a6b58, 467f66896 and f7a41addb.

The comparison tool marks the window's first present (2398 vs 2422) as a configuration difference: the window opens 200 s into each run. Both summaries set trace_dropped, because the worker filled its event buffer at about 2,700 draws per frame. The phase totals above stay complete. The change's summary says a38ad5e9f with dirty, because that build was made from the change's tree before it was committed as b8acbb0d6.

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
  • GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11
  • AI-assisted: yes

Traces and summary lines (baseline b593e36eccba, this change b8acbb0d6, whose summary says a38ad5e9fc89):
coarse-traces.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4870429721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6266). Originally posted by [meh7an](https://github.com/meh7an) on 2026-10-15T08:29:14Z. --- ### What `GuestMemory::UnchangedSince` and `UnchangedSinceAll` answer whether any 64 KiB block of a range was stamped after a generation. #1310 made that a tight scan of the block stamps, but the scan still reads every block of the range. Render targets are checked this way on every draw (`StorageTexture::refreshProved`, from `refreshResidentTarget`), and a 4K surface spans hundreds of blocks. The write tracker now also keeps the newest stamp of each run of 64 blocks (4 MiB), and `stamp` raises it with the block's stamp. `unchanged` skips a whole run whose newest stamp is not after the generation. It scans the other runs, and the partial runs at either end, block by block as before. - Only `initialize` and `stamp` write block stamps, so a run's stamp cannot fall behind its blocks. - On Linux a run never crosses a leaf, because 64 divides `LeafBlocks`. On the S2 page of Sonic Origins Plus's main menu, `UnchangedSince` cost the queue worker (APS5 sampler, 15 s): - before, in two runs: 62 and 86 samples, of which 47 and 60 were its own scan; - with this change: 50 samples, of which 31 were its own scan. Per frame that is 0.76 to 0.44 samples. That is about 0.6% of the worker's frame, so the frame times below move within run-to-run noise. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14. - On main db81992c5 with this change, the full ctest suite passes: 1253 of 1254 tests. The other one, `agc_driver_draw_program_trace`, is not run, because its test executable does not link under MinGW on main itself (`__gxx_personality_v0` is undefined); it does not contain the code changed here. - `agc_write_tracking` has a new check, `CheckCoarseRuns`, over a range of 192 blocks. A driver store inside whole runs and a CPU store into the last block must both be seen, and blocks outside the stored one must stay unchanged. - The check fails ("a driver store inside whole 4 MiB runs of the range is not seen") when `stamp` leaves the run stamp alone. - Sonic Origins Plus, main menu, S2 page (the 3D background), 1233x694 window. - Captured with `APS5_TRACE_SECONDS=200:15` on the same machine in one session, caches warm. Traces attached. - Baseline b593e36eccba, this change b8acbb0d6 (its summary says a38ad5e9fc89, see the note): | Metric | Baseline | This PR | Change | | --- | ---: | ---: | ---: | | frame_ms.p50 | 130.365 | 130.139 | -0.2% | | frame_ms.p90 | 136.606 | 132.568 | -3.0% | | mean_frame_ms | 133.147 | 130.258 | -2.2% | | gpu_busy_ms_per_present | 83.817 | 85.039 | +1.5% | | Driver.Packet (ms per frame) | 130.567 | 127.684 | -2.2% | The median frame did not move. The mean and p90 differences come mostly from a few slow frames in the baseline's window (p99 160.8 against 135.1 ms), which is run-to-run noise at this size. The FPS shown in the title went from 7.91 to 8.34 (median of six readings). The sampled pair, run an hour earlier, showed 7.55 and 7.51, so neither pair moves beyond run-to-run noise. > **Note: measuring base.** These numbers come from my fork's dev, on main 0a56aaaf4, the last main before #5596. On Windows, later mains compare direct imports on every use, which keeps this menu at 3-4 FPS and hides a change of this size. > - The baseline is [measure/tape-2026-10-14](https://github.com/meh7an/AnyPS5/commits/measure/tape-2026-10-14) (b593e36ec). > - This change is [measure/coarse-2026-10-15](https://github.com/meh7an/AnyPS5/commits/measure/coarse-2026-10-15) (b8acbb0d6): the same tree with a test-only fix folded in, plus this change. > > Both carry these commits from my fork: > - the fixes a71073ce3, c0d875634, e3c68960e, 604f0f373 and 10ff693aa (#5778); > - make-exe and the stage dumps (522230d62, deee71fde); > - the crash-report sampler (8d9c3103e..f641e1ec9), which took the profiles; > - #6037, #6066, #6077, #6067, #6082 (its first version, before #5906) and #6095; > - seven smaller steps kept in my fork: e83260247, 97b1ff6c9, 84f5bf0ff, 52704cf7c (covered on main by #5062), c0c3a6b58, 467f66896 and f7a41addb. > > The comparison tool marks the window's first present (2398 vs 2422) as a configuration difference: the window opens 200 s into each run. Both summaries set `trace_dropped`, because the worker filled its event buffer at about 2,700 draws per frame. The phase totals above stay complete. The change's summary says a38ad5e9f with `dirty`, because that build was made from the change's tree before it was committed as b8acbb0d6. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 - [x] GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11 - [x] AI-assisted: yes Traces and summary lines (baseline b593e36eccba, this change b8acbb0d6, whose summary says a38ad5e9fc89): [coarse-traces.zip](https://github.com/user-attachments/files/33482648/coarse-traces.zip)
github-actions[bot] commented 2026-10-15 12:17:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:17:46Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6701 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp L808-820, L825, L859-860, L1056-1065, L1070, L1085-1093

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 4448 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6185 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6234 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6273 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
PR 6868 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
PR 6946 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
PR 7332 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
PR 7615 core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191852180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6266#issuecomment-6191852180). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:17:46Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6701](https://www.github.com/boykopovar/AnyPS5/pull/6701) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` [L808-820](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L808-L820), [L825](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L825), [L859-860](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L859-L860), [L1056-1065](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L1056-L1065), [L1070](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L1070), [L1085-1093](https://github.com/boykopovar/AnyPS5/blob/0d1c299a91bf492ad860fac691200ac6f101608f/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L1085-L1093) | | | 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 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/Execution/src/GuestMemory.cpp` | | [PR 6185](https://www.github.com/boykopovar/AnyPS5/pull/6185) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6186](https://www.github.com/boykopovar/AnyPS5/pull/6186) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6192](https://www.github.com/boykopovar/AnyPS5/pull/6192) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6234](https://www.github.com/boykopovar/AnyPS5/pull/6234) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6273](https://www.github.com/boykopovar/AnyPS5/pull/6273) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp` | | [PR 6868](https://www.github.com/boykopovar/AnyPS5/pull/6868) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp` | | [PR 7615](https://www.github.com/boykopovar/AnyPS5/pull/7615) | `core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` |
github-actions[bot] commented 2026-10-18 19:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:35:54Z.


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:6254236260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6266#issuecomment-6254236260). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T19:35:54Z. --- <!-- 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`.
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!6266
No description provided.