Skip to content

perf(agc): reuse the depth plane collect token within a draw - #17740

Closed
chitters2004 wants to merge 2 commits into
boykopovar:mainfrom
chitters2004:perf/agc-depth-collect-once
Closed

chitters2004 wants to merge 2 commits into
boykopovar:mainfrom
chitters2004:perf/agc-depth-collect-once

Conversation

@chitters2004

@chitters2004 chitters2004 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Title: perf(agc): reuse the depth plane collect token within a draw

What

A draw over a mirrorable depth surface collects the depth plane in SyncFromMemory and the stencil plane in SyncStencilFromMemory, then looks the same spans up again in NoteMemory, in the same collect epoch. That second lookup is normally a collect-memo hit: it walks no pages, but it costs a map lookup and an increment of the shared memo-hit counter, twice per depth-and-stencil draw.

The first collect now hands back a token (GuestMemory::CollectReceipt: the memoized range, the covered range, the issuing thread, the collect epoch, the allocation-mapping generation and the unwatch serial). The two sync functions return it and the draw passes it to NoteMemory; nothing is stored on the surface. GuestMemory::RecollectWrites returns the tracker's published generation only when the token proves the ordinary collector would memo-hit the same request now: same epoch on the thread that issued the token and bumps it, same mapping generation and unwatch serial, and the request inside the token's range (the epoch map covers a contained request). Otherwise it calls the ordinary collector, so a thread that never bumps its epoch, another thread that adopted the epoch, a refused or partial collection, a thread-ring-only hit, a ring eviction, a mapping or watch change, APS5_SHARED_COLLECT_MEMO, APS5_NO_EPOCH_COLLECT_MAP and APS5_NO_COLLECT_MEMO all behave as before. Stores the driver makes between the two points (fast clear, stencil storage take) are absorbed exactly as before. The memo policy stays inside GuestMemory; the graphics code only passes the token on.

Not changed: DepthSurface::CheckCurrent's collects (multisample only, CollectWritesUncached race guards), the debt entries (no behaviour change).

Tested

Windows, RTX 3080, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R 'agc_driver_(depth_|native_depth|native_multisample_depth|graphics$|sample_mask_depth_stencil|gcn_padded_depth)|agc_write_tracking' on main and on this PR from the same tree (measured on the earlier head; the GTA timing below is on 3fb1bd7422 over main d03beaf110): 72 of 72 on main, 76 of 76 here (the PR adds agc_driver_depth_surface_reuse and three agc_driver_depth_store_window_* entries, each about 0.03 s), 0 VUID- lines on both, no missing-layer line.

Head 9348089692 is 3fb1bd7422 merged with main f439f7f3a0; SyncFromMemory keeps main's backing refresh and storing flag and returns the collect receipt. The results here are from 3fb1bd7422 and are not rerun on the merge.
New tests: CheckCollectReceipts in agc_write_tracking exercises the token directly (a first walk, a block-widened walk, reuse inside an unchanged epoch against the memo hit it replaces, a new epoch, a refused and a partial collection clearing the token, a thread-ring-only hit, a contained range after 64 ring evictions (reused exactly when the ordinary collector memo-hits it), a partial unwatch and a remap of the plane itself, and another thread's walk published between the two points with a barrier). TestDepthPlanesCollectedOncePerDraw counts memo hits per steady draw (main plus the test 2 for depth, 4 for depth and stencil; this PR 1 and 2) and checks that a CPU write between draws or after a draw is still seen. TestStoresBetweenObservations checks a stamp, a driver byte store (StoreOwnBytes) or CPU store between the sync and the note on both planes with exact outcomes: absorbed after a new epoch, a mapping change, a watch change or on an unbumped thread, and still seen later when it lands inside an unchanged epoch. The three *_store_window_* entries rerun those cases under APS5_NO_COLLECT_MEMO, APS5_SHARED_COLLECT_MEMO and APS5_NO_EPOCH_COLLECT_MAP.
Mutants (one build, DD_MUTANT): always collecting, a stale repeat sync, the old generation reuse, skipping the whole token validation, skipping only the epoch, unwatch or mapping check, not clearing the token on a refused collection and not honouring the issuing thread and a walker that never reaches its held collect (bounded wait) each fail a named assertion.
rk3 replay with #17338 head, --repeat 5, steady passes, main versus this PR: collect calls per pass 78,991 to about 62,780 (-16,200, about 2 x 8,100), memo hits 73,536 to about 57,330, OverwrittenInMemory/OverwrittenOnGpu true 0 and 0, depth surface retires 4 and creates 4 per pass unchanged, pixels_identical 1.000000.
The rk3 replay is paced and its frames are dominated by Driver.Rewind, so its frame times are not timing evidence for this change; the counts above are the claim (about 16,200 fewer collector lookups per pass, each a map lookup plus a shared counter increment). The GTA timing is below.

Performance. GTA V (PPSA04263, save play1-first-autosave), 3840x2160, RTX 3080, driver 621.14, Windows 11 (10.0.26320), Ryzen 7 5800X, APS5_TRACE_SECONDS=235:30 with APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1. Main d03beaf110 (A) against this PR 3fb1bd7422 (C): one warm-up boot per side (discarded), then three timed pairs in the order A C, C A, A C. Every run is a fresh boot from the same save, with a preflight check and a timing claim; all lines dirty: false; every capture dropped trace events.

run commit presents mean ms/frame p50 p90 p99 Driver.Draw.prepare ms/frame
a1 d03beaf 246 122.03 121.5 125.3 147.0 63.8
c1 3fb1bd7 239 125.95 125.5 129.8 137.4 66.8
c2 3fb1bd7 243 123.67 123.1 127.2 142.9 65.0
a2 d03beaf 237 126.59 123.6 128.4 158.1 67.7
a3 d03beaf 241 124.63 124.2 128.9 137.1 65.6
c3 3fb1bd7 236 127.16 126.1 132.2 149.4 67.8

Pair deltas C minus A: +3.92, -2.92, +2.53 ms/frame, mean +1.18 ms (+0.9 %), range -2.92 to +3.92; the A runs alone span 4.56 ms. The change is inside the noise: this PR removes about 16,200 collector lookups per pass (the counts above), which at a map lookup each is well below what a 3,040-draw frame at about 125 ms can resolve (+0.4 us per draw, range -1.0 to +1.3). Driver.Draw.prepare moves +3.0, -2.7, +2.2 ms/frame with the same sign as the frame time, so the PR's collect saving is not visible in the zones either. I am not claiming a frame-time gain; the claim is the counted reduction.

The two summary lines below are the first pair (all runs, traces, digests and compares are in the release https://github.com/chitters2004/AnyPS5/releases/tag/pr-dedupe-t5):

{"commit":"d03beaf11059","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":""},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4182,"ms":30019.206},"presents":246,"frame_ms":{"p50":121.492,"p90":125.296,"p99":147.006,"max":150.669},"gpu_busy_ms_per_present":32.8,"worker_busy_pct":{"queue worker 0x0":94.5},"top_phases_ms_per_frame":{"Driver.Packet":109.256,"Graphics.Draw":92.843,"Driver.Packet.draw":80.086,"Driver.Draw":79.496,"Graphics.Draw.draw_and_resource_release":72.459,"Driver.DrawFinish":70.525,"Driver.Draw.prepare":63.845,"Driver.DrawFinish.draw_enqueued":39.031},"owned_draw_counts":{"OwnedDraw.arm_attempt":738,"OwnedDraw.arm_blocks_requested":738,"OwnedDraw.arm_refused":738,"OwnedDraw.evicted_other":2065},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.658,"events_lost":1136551,"totals_full":false},"draw committer":{"events_full_after_s":11.064,"events_lost":447799,"totals_full":false},"draw finisher":{"events_full_after_s":16.124,"events_lost":224836,"totals_full":false}},"trace":"aps5-trace-d03beaf11059-22608.json.gz"}

{"commit":"3fb1bd74229e","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":""},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4130,"ms":30102.994},"presents":239,"frame_ms":{"p50":125.485,"p90":129.754,"p99":137.446,"max":156.567},"gpu_busy_ms_per_present":33.048,"worker_busy_pct":{"queue worker 0x0":94.923},"top_phases_ms_per_frame":{"Driver.Packet":113.221,"Graphics.Draw":96.469,"Driver.Packet.draw":83.336,"Driver.Draw":82.738,"Graphics.Draw.draw_and_resource_release":75.05,"Driver.DrawFinish":73.284,"Driver.Draw.prepare":66.844,"Driver.DrawFinish.draw_enqueued":40.414},"owned_draw_counts":{"OwnedDraw.arm_attempt":717,"OwnedDraw.arm_blocks_requested":717,"OwnedDraw.arm_refused":717,"OwnedDraw.evicted_other":2019},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.491,"events_lost":1169789,"totals_full":false},"draw committer":{"events_full_after_s":10.733,"events_lost":472533,"totals_full":false},"draw finisher":{"events_full_after_s":15.504,"events_lost":246818,"totals_full":false}},"trace":"aps5-trace-3fb1bd74229e-6468.json.gz"}

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080, Windows 11 (the AGC depth tests above; driver 621.14)
  • AI-assisted: yes

Overlap to note when posting: #15058 changes WrittenUnits and SyncFromMemory signatures and the same call site; #9895 edits the adjacent SyncFromMemory line. Both will need a trivial rebase either way.

🤖 Generated with Claude Code

A draw over a mirrorable depth surface collected the depth and stencil planes in
SyncFromMemory and SyncStencilFromMemory and looked the same span up again in
NoteMemory, in the same collect epoch. That second lookup is normally a collect-memo hit:
it walks no pages, but it costs a map lookup and an increment of the shared memo-hit
counter. The first collect now hands back a token (CollectReceipt: the memoized range, the
covered range, the collect epoch, the allocation-mapping generation and the unwatch
serial); the sync functions return it and the draw passes it to NoteMemory.

GuestMemory::RecollectWrites returns the tracker's published generation only when the
token proves the ordinary collector would memo-hit the same request now: same epoch on a
thread that bumps it and issued the token, same mapping generation and unwatch
serial, and the request inside the token's range, which the epoch map covers. In every
other case, including a thread that never bumps its epoch, another thread that adopted the
epoch, a refused or partial collection,
a thread-ring-only hit, a ring eviction, a mapping or watch change, a shared memo and
APS5_NO_COLLECT_MEMO, it calls the ordinary collector. Stores the driver makes between the
two points are absorbed exactly as before.

Adds CollectReceipt, a CollectWrites overload that fills it, RecollectWrites and the
counters CollectMemoHits, CollectWalks and ThreadReceiptReuses. A new debt entry says a
note can absorb a write another thread published after the sync. WriteTracking tests cover the token directly; the depth tests count the
lookups per draw and check stores between the two points on both planes; focused ctest
entries run those under APS5_NO_COLLECT_MEMO, APS5_SHARED_COLLECT_MEMO and
APS5_NO_EPOCH_COLLECT_MAP.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the perf Performance change label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

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 16644 core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp L781
PR 17786 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp L322, L1984-1985

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 1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6186 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6548 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6804 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7002 docs/dev/debt/libSceAgcDriver.md
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7449 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7604 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7642 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake
docs/dev/debt/libSceAgcDriver.md
PR 8212 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8592 docs/dev/debt/libSceAgcDriver.md
PR 8707 docs/dev/debt/libSceAgcDriver.md
PR 9356 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9387 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9592 docs/dev/debt/libSceAgcDriver.md
PR 9748 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9915 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9950 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10049 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10193 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake
docs/dev/debt/libSceAgcDriver.md
PR 10249 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10359 docs/dev/debt/libSceAgcDriver.md
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 11587 docs/dev/debt/libSceAgcDriver.md
PR 12904 docs/dev/debt/libSceAgcDriver.md
PR 13809 docs/dev/debt/libSceAgcDriver.md
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 13928 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake
docs/dev/debt/libSceAgcDriver.md
PR 13929 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake
docs/dev/debt/libSceAgcDriver.md
PR 14212 docs/dev/debt/libSceAgcDriver.md
PR 14344 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 14944 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake
docs/dev/debt/libSceAgcDriver.md
PR 15058 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 15136 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 15529 docs/dev/debt/libSceAgcDriver.md
PR 15570 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 16260 docs/dev/debt/libSceAgcDriver.md
PR 16879 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 16880 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 16884 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_write_tracking_tests.cmake
PR 16935 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 17024 docs/dev/debt/libSceAgcDriver.md
PR 17573 docs/dev/debt/libSceAgcDriver.md
PR 17796 docs/dev/debt/libSceAgcDriver.md

@milescoviello milescoviello left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the receipt against the memo hit it replaces.

  • Keys: in collectWrites, a memo hit returns tracker.stable when epochCollectMap(epoch, unwatched, mapping).Covers(first, stop). RecollectWrites returns the same tracker.stable when the receipt's epoch, unwatch serial and mapping generation all equal the current ones, and the requested pages lie inside the receipt's [first, stop). Those are the three keys the epoch map is indexed by, and it only ever gains ranges within an epoch, so a valid receipt answers exactly what the map lookup would.
  • Thread: the issuing-thread check covers the non-shared case, where the memo is per thread. With sharedCollectMemo() the receipt is never set, so that path is unchanged.
  • Issue points: the receipt is filled only on a memo hit or after a walk that recorded its range, and is reset at the top of each collectWrites. A refused or partial walk leaves it empty, which the new CheckCollectReceipts cases pin.

On the evidence, as you note, the GTA V pairs are inside the noise. That includes the phase the change targets: Driver.Draw.prepare is 63.8–67.7 ms on main and 65.0–67.8 ms with this. What the PR shows is the count, about 16,200 fewer collector lookups per pass, each a map lookup that was already a hit. That's a fair cleanup claim, but not a measured speed-up yet. A title whose committer spends visibly in collectWrites, such as a perf/sampler line where its share drops, would make it one.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 9, 2026
SyncFromMemory keeps main's write-index backing refresh and storing flag and
returns the collect receipt that the draw hands to NoteMemory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 9, 2026
@chitters2004

Copy link
Copy Markdown
Contributor Author

Closing this. A microbenchmark shows the token costs more than the lookups it saves.

GuestMemory collect on one thread, 64 KiB block, same collect epoch (the case this PR targets), main d03beaf110 against this PR, A B B A x5, medians in ns:

main this PR
plain collect 15.0 14.5
first collect (with token on this PR) 15.0 41.7
first collect + second lookup (RecollectWrites on this PR) 29.9 90.0

The second lookup this PR removes is already a 15 ns memo hit on main, so the most it could save is about 0.24 ms per pass (16,200 pairs). Filling and checking the token costs about 1 ms per pass instead. The GTA V sampler run on the earlier head agreed within its noise (collectWrites 9.5 % to 9.9 % of committer samples, +0.4 +-1.3).

Source, script and runs: https://github.com/chitters2004/AnyPS5/releases/tag/pr-dedupe-t5 (pr17740-microbench.tar.gz).

The per-draw collect and lookup work this touches is better removed as a whole (per-block dirty state and resource versions) than trimmed by one lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants