perf(libc): skip never-written pages when evicting a resident direct-memory run #12227

Merged
klosixgaming-arch merged 1 commit from upstream-pr/12227 into main 2026-10-29 22:01:15 +00:00
klosixgaming-arch commented 2026-10-28 03:58:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-28T03:58:58Z.


What

On Windows, releasing a resident direct-memory run (WindowsMappings::evict) read every page of it with blank(). Reading a committed page that was never written faults in a zeroed page, and about 97% of the pages Soul Hackers 2 releases were never written. The scan cost 2.9 us per page and held the guest-allocation registry mutex for about 7 s of every 10 s, which is what limited the CPU side of its light scene.

The run's GetWriteWatch is now read once (after the run is made read-only) and blank() is only called for the pages it lists. That is only done when the list is complete: the run was committed with MEM_WRITE_WATCH, no collection has cleared its watch (Run::reset), and no host import touched it (Run::imported, because GPU writes through an import are not seen by the write watch). Otherwise, and if GetWriteWatch fails, the old full scan runs, so APS5_NO_WRITE_WATCH keeps the old behaviour.

Where the time went (timers inside evict, 10 s window, light scene, before the change): total 3,340 ms, blank() 2,979 ms, VirtualProtect 74 ms, views.erase 113 ms, copy of written pages 31 ms; 1,029,031 pages scanned, 26,670 written. Scanning the same pages a second time took 181 ms, and an SSE2 blank() changed nothing, so the cost is the first-touch faults. With the change (probe build): mutations holding the registry mutex 7.1 s -> 1.5 s per 10 s, lookups waiting on it 4.4 s -> 0.47 s, evict 0.53 s per 10 s.

Tested

Windows 10.0.26200, RTX 5090 (NVIDIA 617.42), Ryzen 9 9950X3D, Soul Hackers 2 (PPSA03743) from the start of the game, on the same machine and in the same session. Both builds were captured with APS5_TRACE_FRAMES=400:180 (the same 180 game frames, from present 400, so first_present matches) and no other APS5_TRACE_*/APS5_PROFILE_* switch, one run each, main first. The caches were warm.

  • main 2227f1366188: aps5-trace-2227f1366188-12632.json.gz
  • this branch e21aa4cabddf (rebased on that main): aps5-trace-e21aa4cabddf-23548.json.gz

The traces are attached in the comment below.

aps5-summary.jsonl line, main:

{"commit":"2227f1366188","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":4628.394},"presents":180,"frame_ms":{"p50":25.206,"p90":29.996,"p99":38.132,"max":41.365},"gpu_busy_ms_per_present":1.249,"worker_busy_pct":{"queue worker 0x0":96.352},"top_phases_ms_per_frame":{"Driver.Packet":24.772,"Driver.Packet.dispatch":16.341,"Driver.Dispatch":8.989,"Graphics.Draw":6.689,"Graphics.Draw.draw_and_resource_release":6.272,"Vulkan.Dispatch":4.613,"VideoOut.Flip":4.559,"Resources.Complete":4.274},"trace_dropped":false,"trace":"aps5-trace-2227f1366188-12632.json.gz"}

aps5-summary.jsonl line, this branch:

{"commit":"e21aa4cabddf","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":3052.999},"presents":180,"frame_ms":{"p50":16.684,"p90":16.858,"p99":17.096,"max":70.738},"gpu_busy_ms_per_present":1.130,"worker_busy_pct":{"queue worker 0x0":37.443},"top_phases_ms_per_frame":{"VideoOut.Flip":16.170,"VideoOut.Flip.vblank_wait":15.224,"Driver.Packet":6.349,"Graphics.Draw":3.920,"Graphics.Draw.draw_and_resource_release":3.668,"Driver.Packet.draw":2.262,"Driver.Draw":2.252,"Driver.Packet.dispatch":2.245},"trace_dropped":false,"trace":"aps5-trace-e21aa4cabddf-23548.json.gz"}

tools/performance_compare.py on those two lines:

Performance comparison

Capture Commit Trace Presents Window (ms)
baseline 2227f13661 aps5-trace-2227f1366188-12632.json.gz 180 4628.394
candidate e21aa4cabd aps5-trace-e21aa4cabddf-23548.json.gz 180 3052.999
  • Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene.
  • Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval.
  • A missing top phase is unreported, not zero; its change is unavailable.

Frame and GPU times (ms)

Metric Baseline Candidate Change Change (%)
frame_ms.p50 25.206 16.684 -8.522 -33.809
frame_ms.p90 29.996 16.858 -13.138 -43.799
frame_ms.p99 38.132 17.096 -21.036 -55.166
frame_ms.max 41.365 70.738 +29.373 +71.009
mean_frame_ms 25.713 16.961 -8.752 -34.038
gpu_busy_ms_per_present 1.249 1.130 -0.119 -9.528

Top phases (ms per frame)

Metric Baseline Candidate Change Change (%)
Driver.Dispatch 8.989 n/a n/a n/a
Driver.Draw n/a 2.252 n/a n/a
Driver.Packet 24.772 6.349 -18.423 -74.370
Driver.Packet.dispatch 16.341 2.245 -14.096 -86.262
Driver.Packet.draw n/a 2.262 n/a n/a
Graphics.Draw 6.689 3.920 -2.769 -41.396
Graphics.Draw.draw_and_resource_release 6.272 3.668 -2.604 -41.518
Resources.Complete 4.274 n/a n/a n/a
VideoOut.Flip 4.559 16.170 +11.611 +254.683
VideoOut.Flip.vblank_wait n/a 15.224 n/a n/a
Vulkan.Dispatch 4.613 n/a n/a n/a

The only slow frame on the branch (present 448, 70.7 ms) is a graphics pipeline build (Vulkan.GraphicsPipelinePrebuild), not the change; the other 179 frames are 17.1 ms or less, at the 60 Hz limit (VideoOut.Flip.vblank_wait). On main the queue worker is busy 96% of the time.

tools/trace_digest.py, main

frames 400:180 from present 400: 180 presents, frame p50 25.2 / p90 30.0 / p99 38.1 / max 41.4 ms, GPU busy 1.2 ms per present
NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit 2227f13661, dropped: no

{"commit":"2227f1366188","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":4628.394},"presents":180,"frame_ms":{"p50":25.206,"p90":29.996,"p99":38.132,"max":41.365},"gpu_busy_ms_per_present":1.249,"worker_busy_pct":{"queue worker 0x0":96.352},"top_phases_ms_per_frame":{"Driver.Packet":24.772,"Driver.Packet.dispatch":16.341,"Driver.Dispatch":8.989,"Graphics.Draw":6.689,"Graphics.Draw.draw_and_resource_release":6.272,"Vulkan.Dispatch":4.613,"VideoOut.Flip":4.559,"Resources.Complete":4.274},"trace_dropped":false,"trace":"aps5-trace-2227f1366188-12632.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 555: 41.4 ms at 3923 ms: Driver.Packet (queue worker 0x0) 39.7, Driver.Packet.dispatch (queue worker 0x0) 12.3, Driver.Packet.draw (queue worker 0x0) 10.1, Driver.Draw (queue worker 0x0) 10.1
  • present 574: 38.1 ms at 4459 ms: Driver.Packet (queue worker 0x0) 37.0, Driver.Packet.dispatch (queue worker 0x0) 17.1, Driver.Dispatch (queue worker 0x0) 9.3, Vulkan.Dispatch (queue worker 0x0) 9.1
  • present 476: 37.9 ms at 1913 ms: Driver.Packet (queue worker 0x0) 36.7, Driver.Packet.dispatch (queue worker 0x0) 19.1, Graphics.Draw (draw committer) 17.4, Graphics.Draw.draw_and_resource_release (draw committer) 17.0
  • present 552: 35.7 ms at 3823 ms: Driver.Packet (queue worker 0x0) 34.4, Driver.Packet.dispatch (queue worker 0x0) 16.4, Driver.Dispatch (queue worker 0x0) 9.7, Driver.Dispatch.decode_key_device_setup (queue worker 0x0) 7.4
  • present 553: 35.6 ms at 3859 ms: Driver.Packet (queue worker 0x0) 33.4, Driver.Packet.dispatch (queue worker 0x0) 19.6, Driver.Dispatch (queue worker 0x0) 10.9, Graphics.Draw (draw committer) 7.5

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
queue worker 0x0 24.1 (94 %) 0.9 (4 %) 0.6 1.9 Driver.Packet 24.2, Driver.Completion 0.0
draw committer 7.2 (28 %) 0.6 (2 %) 18.0 0.3 Graphics.Draw 6.7, Vulkan.DrawFromRecipe 0.3
presenter 4.5 (17 %) 0.1 (0 %) 21.1 0.1 VideoOut.Flip 4.6, Driver.Present 0.0
title 0.0 (0 %) 0.0 (0 %) 25.7 0.0 Recorder.Sync 0.0
title 0.6 (2 %) 0.1 (0 %) 25.1 0.3 Recorder.Sync 0.5, Shader.ResolveGraphicsStagesAbi 0.0
gpu 1.2 (5 %) 0.0 (0 %) 24.5 0.0 batch 1.2

Largest slices (ms per frame, inclusive, all threads): Driver.Packet 24.2, Driver.Packet.dispatch 16.3, Driver.Dispatch 9.0, Graphics.Draw 6.7, Graphics.Draw.draw_and_resource_release 6.2, Vulkan.Dispatch 4.6, VideoOut.Flip 4.6, Driver.Dispatch.decode_key_device_setup 4.3, Resources.Complete 4.3, Vulkan.Dispatch.shader_resources 3.4

Longest waits

  • Driver.Packet.rendering_wait (queue worker 0x0) 6.7 ms at 1092 ms, present 442
  • Driver.Present.gpu_mutex_wait (presenter) 6.2 ms at 274 ms, present 410
  • Driver.Packet.rendering_wait (queue worker 0x0) 4.2 ms at 1476 ms, present 457
  • Driver.Packet.rendering_wait (queue worker 0x0) 4.0 ms at 2088 ms, present 483
  • Driver.Present.gpu_mutex_wait (presenter) 2.8 ms at 3894 ms, present 554
  • GpuMutex.wait.label (draw committer) 2.0 ms at 3202 ms, present 528
  • GpuMutex.wait.flush (draw committer) 1.7 ms at 3848 ms, present 552
  • GpuMutex.wait.dispatch (queue worker 0x0) 1.6 ms at 3980 ms, present 556
  • Driver.WorkerWait (queue worker 0x0) 1.4 ms at 1801 ms, present 470
  • Driver.WorkerWait (queue worker 0x0) 1.4 ms at 2656 ms, present 506

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 793: 1.3 ms at 2429 ms, present 496: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.8, Recorder.Submit (draw committer) 0.0, Graphics.Draw.validate (draw committer) 0.0
  • batch 1434: 1.2 ms at 4367 ms, present 570: GPU no ranges; recorded by GpuMutex.wait.flush (draw committer) 1.3, Graphics.Draw (draw committer) 1.3, Graphics.Draw.draw_and_resource_release (draw committer) 1.3
  • batch 1093: 1.1 ms at 3282 ms, present 531: GPU no ranges; recorded by Graphics.Draw (draw committer) 2.4, Graphics.Draw.draw_and_resource_release (draw committer) 2.3, Resources.Complete (draw committer) 0.9, Resources.Prepare (draw committer) 0.2
  • batch 636: 1.0 ms at 1947 ms, present 476: GPU no ranges; recorded by Graphics.Draw (draw committer) 13.4, Graphics.Draw.draw_and_resource_release (draw committer) 13.3, Resources.Complete (draw committer) 11.4, Resources.Prepare (draw committer) 0.2
  • batch 698: 1.0 ms at 2133 ms, present 484: GPU no ranges; recorded by Graphics.Draw (draw committer) 2.0, Graphics.Draw.draw_and_resource_release (draw committer) 1.9, Resources.Complete (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
tools/trace_digest.py, this branch

frames 400:180 from present 400: 180 presents, frame p50 16.7 / p90 16.9 / p99 17.1 / max 70.7 ms, GPU busy 1.1 ms per present
NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit e21aa4cabd, dropped: no

{"commit":"e21aa4cabddf","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":3052.999},"presents":180,"frame_ms":{"p50":16.684,"p90":16.858,"p99":17.096,"max":70.738},"gpu_busy_ms_per_present":1.13,"worker_busy_pct":{"queue worker 0x0":37.443},"top_phases_ms_per_frame":{"VideoOut.Flip":16.17,"VideoOut.Flip.vblank_wait":15.224,"Driver.Packet":6.349,"Graphics.Draw":3.92,"Graphics.Draw.draw_and_resource_release":3.668,"Driver.Packet.draw":2.262,"Driver.Draw":2.252,"Driver.Packet.dispatch":2.245},"trace_dropped":false,"trace":"aps5-trace-e21aa4cabddf-23548.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 448: 70.7 ms at 801 ms: Vulkan.GraphicsPipelinePrebuild (shader prepare) 129.1, Vulkan.GraphicsPipeline (shader prepare) 129.0, Vulkan.GraphicsPipelineLibrary (shader prepare) 129.0, Driver.Packet (queue worker 0x0) 70.2
  • present 442: 17.1 ms at 701 ms: VideoOut.Flip (presenter) 17.0, VideoOut.Flip.vblank_wait (presenter) 15.7, Driver.WorkerWait (queue worker 0x0) 10.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 10.2
  • present 414: 17.0 ms at 233 ms: VideoOut.Flip (presenter) 16.7, VideoOut.Flip.vblank_wait (presenter) 15.8, Driver.WorkerWait (queue worker 0x0) 11.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 11.4
  • present 571: 17.0 ms at 2903 ms: VideoOut.Flip (presenter) 16.8, VideoOut.Flip.vblank_wait (presenter) 15.9, Driver.WorkerWait (queue worker 0x0) 11.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 11.4
  • present 534: 17.0 ms at 2285 ms: VideoOut.Flip (presenter) 16.7, VideoOut.Flip.vblank_wait (presenter) 16.0, Driver.WorkerWait (queue worker 0x0) 10.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 10.8

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
queue worker 0x0 5.9 (35 %) 10.5 (62 %) 0.6 1.7 Driver.Packet 5.9
draw committer 4.1 (24 %) 0.5 (3 %) 12.3 0.4 Graphics.Draw 3.9, Vulkan.DrawFromRecipe 0.1
presenter 1.0 (6 %) 15.3 (90 %) 0.7 0.1 VideoOut.Flip 16.2, Driver.Present 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 16.9 0.0 Shader.PrepareArtifact 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.1 (1 %) 0.0 (0 %) 16.9 0.0 Vulkan.GraphicsPipelinePrebuild 0.1
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.4 (2 %) 0.0 (0 %) 16.6 0.0 Vulkan.GraphicsPipelinePrebuild 0.4
shader prepare 0.4 (3 %) 0.0 (0 %) 16.5 0.0 Vulkan.GraphicsPipelinePrebuild 0.4
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
shader prepare 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Vulkan.GraphicsPipelinePrebuild 0.0
title 0.6 (4 %) 0.1 (0 %) 16.3 0.3 Recorder.Sync 0.5, Shader.ResolveAbi 0.1
title 0.0 (0 %) 0.0 (0 %) 17.0 0.0 Shader.Register 0.0
gpu 1.1 (7 %) 0.0 (0 %) 15.8 0.0 batch 1.1

Largest slices (ms per frame, inclusive, all threads): VideoOut.Flip 16.2, VideoOut.Flip.vblank_wait 15.2, Driver.WorkerWait 10.5, Driver.WorkerWait.idle_and_completion_poll 10.5, Driver.Packet 5.9, Graphics.Draw 3.9, Graphics.Draw.draw_and_resource_release 3.6, Driver.Packet.dispatch 2.2, Driver.Packet.draw 2.1, Driver.Draw 2.1

Longest waits

  • Driver.WorkerWait (queue worker 0x0) 31.3 ms at 767 ms, present 445
  • Driver.WorkerWait (queue worker 0x0) 21.5 ms at 718 ms, present 443
  • VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2286 ms, present 534
  • VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2403 ms, present 541
  • VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2186 ms, present 528
  • VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2153 ms, present 526
  • VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 635 ms, present 438
  • VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 2904 ms, present 571
  • VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 2136 ms, present 525
  • VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 1986 ms, present 516

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 640: 1.8 ms at 1594 ms, present 492: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.3, Graphics.Draw.draw_and_resource_release (draw committer) 1.2, Graphics.Draw.validate (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
  • batch 382: 1.6 ms at 993 ms, present 456: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.9, Resources.Complete (draw committer) 0.5, Resources.Prepare (draw committer) 0.1
  • batch 833: 1.6 ms at 2027 ms, present 518: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.9, Resources.Complete (draw committer) 0.2, Resources.Prepare (draw committer) 0.2
  • batch 1213: 1.6 ms at 3029 ms, present 578: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.6, Graphics.Draw.draw_and_resource_release (draw committer) 1.5, Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1
  • batch 398: 1.6 ms at 1027 ms, present 458: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.2, Graphics.Draw.draw_and_resource_release (draw committer) 1.2, Vulkan.DrawFromRecipe (draw committer) 0.3, Graphics.DrawWithRecipe (draw committer) 0.3

Where the time went before the change (timers inside evict, 10 s window, light scene): total 3,340 ms, blank() 2,979 ms, VirtualProtect 74 ms, views.erase 113 ms, copy of written pages 31 ms; 1,029,031 pages scanned, 26,670 written. Scanning the same pages a second time took 181 ms, and an SSE2 blank() changed nothing, so the cost is the first-touch faults. With the change: mutations holding the registry mutex 7.1 s -> 1.5 s per 10 s, lookups waiting on it 4.4 s -> 0.47 s, evict 0.53 s per 10 s.

The heavy scene later in the game is GPU-bound and I see no difference there.

Tests: windows_mappings_release passes on the rebased branch (CheckTouchedPagesAnyOrder, CheckEvictKeepsWrittenPages, which fails if Run::reset handling or the markImported call is removed).

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: n/a (no AGC, shader recompiler or VideoOut change)
  • AI-assisted: yes. Written with AI assistance and reviewed by me.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5044983955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12227). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-28T03:58:58Z. --- ### What On Windows, releasing a resident direct-memory run (`WindowsMappings::evict`) read every page of it with `blank()`. Reading a committed page that was never written faults in a zeroed page, and about 97% of the pages Soul Hackers 2 releases were never written. The scan cost 2.9 us per page and held the guest-allocation registry mutex for about 7 s of every 10 s, which is what limited the CPU side of its light scene. The run's `GetWriteWatch` is now read once (after the run is made read-only) and `blank()` is only called for the pages it lists. That is only done when the list is complete: the run was committed with `MEM_WRITE_WATCH`, no collection has cleared its watch (`Run::reset`), and no host import touched it (`Run::imported`, because GPU writes through an import are not seen by the write watch). Otherwise, and if `GetWriteWatch` fails, the old full scan runs, so `APS5_NO_WRITE_WATCH` keeps the old behaviour. Where the time went (timers inside `evict`, 10 s window, light scene, before the change): total 3,340 ms, `blank()` 2,979 ms, VirtualProtect 74 ms, views.erase 113 ms, copy of written pages 31 ms; 1,029,031 pages scanned, 26,670 written. Scanning the same pages a second time took 181 ms, and an SSE2 `blank()` changed nothing, so the cost is the first-touch faults. With the change (probe build): mutations holding the registry mutex 7.1 s -> 1.5 s per 10 s, lookups waiting on it 4.4 s -> 0.47 s, `evict` 0.53 s per 10 s. ### Tested Windows 10.0.26200, RTX 5090 (NVIDIA 617.42), Ryzen 9 9950X3D, Soul Hackers 2 (PPSA03743) from the start of the game, on the same machine and in the same session. Both builds were captured with `APS5_TRACE_FRAMES=400:180` (the same 180 game frames, from present 400, so `first_present` matches) and no other `APS5_TRACE_*`/`APS5_PROFILE_*` switch, one run each, `main` first. The caches were warm. - `main` `2227f1366188`: `aps5-trace-2227f1366188-12632.json.gz` - this branch `e21aa4cabddf` (rebased on that `main`): `aps5-trace-e21aa4cabddf-23548.json.gz` The traces are attached in the comment below. `aps5-summary.jsonl` line, `main`: ```json {"commit":"2227f1366188","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":4628.394},"presents":180,"frame_ms":{"p50":25.206,"p90":29.996,"p99":38.132,"max":41.365},"gpu_busy_ms_per_present":1.249,"worker_busy_pct":{"queue worker 0x0":96.352},"top_phases_ms_per_frame":{"Driver.Packet":24.772,"Driver.Packet.dispatch":16.341,"Driver.Dispatch":8.989,"Graphics.Draw":6.689,"Graphics.Draw.draw_and_resource_release":6.272,"Vulkan.Dispatch":4.613,"VideoOut.Flip":4.559,"Resources.Complete":4.274},"trace_dropped":false,"trace":"aps5-trace-2227f1366188-12632.json.gz"} ``` `aps5-summary.jsonl` line, this branch: ```json {"commit":"e21aa4cabddf","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":3052.999},"presents":180,"frame_ms":{"p50":16.684,"p90":16.858,"p99":17.096,"max":70.738},"gpu_busy_ms_per_present":1.130,"worker_busy_pct":{"queue worker 0x0":37.443},"top_phases_ms_per_frame":{"VideoOut.Flip":16.170,"VideoOut.Flip.vblank_wait":15.224,"Driver.Packet":6.349,"Graphics.Draw":3.920,"Graphics.Draw.draw_and_resource_release":3.668,"Driver.Packet.draw":2.262,"Driver.Draw":2.252,"Driver.Packet.dispatch":2.245},"trace_dropped":false,"trace":"aps5-trace-e21aa4cabddf-23548.json.gz"} ``` `tools/performance_compare.py` on those two lines: # Performance comparison | Capture | Commit | Trace | Presents | Window (ms) | | --- | --- | --- | ---: | ---: | | baseline | 2227f1366188 | aps5-trace-2227f1366188-12632.json.gz | 180 | 4628.394 | | candidate | e21aa4cabddf | aps5-trace-e21aa4cabddf-23548.json.gz | 180 | 3052.999 | - Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene. - Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval. - A missing top phase is unreported, not zero; its change is unavailable. ## Frame and GPU times (ms) | Metric | Baseline | Candidate | Change | Change (%) | | --- | ---: | ---: | ---: | ---: | | frame_ms.p50 | 25.206 | 16.684 | -8.522 | -33.809 | | frame_ms.p90 | 29.996 | 16.858 | -13.138 | -43.799 | | frame_ms.p99 | 38.132 | 17.096 | -21.036 | -55.166 | | frame_ms.max | 41.365 | 70.738 | +29.373 | +71.009 | | mean_frame_ms | 25.713 | 16.961 | -8.752 | -34.038 | | gpu_busy_ms_per_present | 1.249 | 1.130 | -0.119 | -9.528 | ## Top phases (ms per frame) | Metric | Baseline | Candidate | Change | Change (%) | | --- | ---: | ---: | ---: | ---: | | Driver.Dispatch | 8.989 | n/a | n/a | n/a | | Driver.Draw | n/a | 2.252 | n/a | n/a | | Driver.Packet | 24.772 | 6.349 | -18.423 | -74.370 | | Driver.Packet.dispatch | 16.341 | 2.245 | -14.096 | -86.262 | | Driver.Packet.draw | n/a | 2.262 | n/a | n/a | | Graphics.Draw | 6.689 | 3.920 | -2.769 | -41.396 | | Graphics.Draw.draw_and_resource_release | 6.272 | 3.668 | -2.604 | -41.518 | | Resources.Complete | 4.274 | n/a | n/a | n/a | | VideoOut.Flip | 4.559 | 16.170 | +11.611 | +254.683 | | VideoOut.Flip.vblank_wait | n/a | 15.224 | n/a | n/a | | Vulkan.Dispatch | 4.613 | n/a | n/a | n/a | The only slow frame on the branch (present 448, 70.7 ms) is a graphics pipeline build (`Vulkan.GraphicsPipelinePrebuild`), not the change; the other 179 frames are 17.1 ms or less, at the 60 Hz limit (`VideoOut.Flip.vblank_wait`). On `main` the queue worker is busy 96% of the time. <details><summary>tools/trace_digest.py, main</summary> **frames 400:180** from present 400: 180 presents, frame p50 25.2 / p90 30.0 / p99 38.1 / max 41.4 ms, GPU busy 1.2 ms per present NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit 2227f1366188, dropped: no ```json {"commit":"2227f1366188","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":4628.394},"presents":180,"frame_ms":{"p50":25.206,"p90":29.996,"p99":38.132,"max":41.365},"gpu_busy_ms_per_present":1.249,"worker_busy_pct":{"queue worker 0x0":96.352},"top_phases_ms_per_frame":{"Driver.Packet":24.772,"Driver.Packet.dispatch":16.341,"Driver.Dispatch":8.989,"Graphics.Draw":6.689,"Graphics.Draw.draw_and_resource_release":6.272,"Vulkan.Dispatch":4.613,"VideoOut.Flip":4.559,"Resources.Complete":4.274},"trace_dropped":false,"trace":"aps5-trace-2227f1366188-12632.json.gz"} ``` **Slowest frames** (largest slices inside each, inclusive) - present 555: 41.4 ms at 3923 ms: Driver.Packet (queue worker 0x0) 39.7, Driver.Packet.dispatch (queue worker 0x0) 12.3, Driver.Packet.draw (queue worker 0x0) 10.1, Driver.Draw (queue worker 0x0) 10.1 - present 574: 38.1 ms at 4459 ms: Driver.Packet (queue worker 0x0) 37.0, Driver.Packet.dispatch (queue worker 0x0) 17.1, Driver.Dispatch (queue worker 0x0) 9.3, Vulkan.Dispatch (queue worker 0x0) 9.1 - present 476: 37.9 ms at 1913 ms: Driver.Packet (queue worker 0x0) 36.7, Driver.Packet.dispatch (queue worker 0x0) 19.1, Graphics.Draw (draw committer) 17.4, Graphics.Draw.draw_and_resource_release (draw committer) 17.0 - present 552: 35.7 ms at 3823 ms: Driver.Packet (queue worker 0x0) 34.4, Driver.Packet.dispatch (queue worker 0x0) 16.4, Driver.Dispatch (queue worker 0x0) 9.7, Driver.Dispatch.decode_key_device_setup (queue worker 0x0) 7.4 - present 553: 35.6 ms at 3859 ms: Driver.Packet (queue worker 0x0) 33.4, Driver.Packet.dispatch (queue worker 0x0) 19.6, Driver.Dispatch (queue worker 0x0) 10.9, Graphics.Draw (draw committer) 7.5 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | queue worker 0x0 | 24.1 (94 %) | 0.9 (4 %) | 0.6 | 1.9 | Driver.Packet 24.2, Driver.Completion 0.0 | | draw committer | 7.2 (28 %) | 0.6 (2 %) | 18.0 | 0.3 | Graphics.Draw 6.7, Vulkan.DrawFromRecipe 0.3 | | presenter | 4.5 (17 %) | 0.1 (0 %) | 21.1 | 0.1 | VideoOut.Flip 4.6, Driver.Present 0.0 | | title | 0.0 (0 %) | 0.0 (0 %) | 25.7 | 0.0 | Recorder.Sync 0.0 | | title | 0.6 (2 %) | 0.1 (0 %) | 25.1 | 0.3 | Recorder.Sync 0.5, Shader.ResolveGraphicsStagesAbi 0.0 | | gpu | 1.2 (5 %) | 0.0 (0 %) | 24.5 | 0.0 | batch 1.2 | **Largest slices** (ms per frame, inclusive, all threads): Driver.Packet 24.2, Driver.Packet.dispatch 16.3, Driver.Dispatch 9.0, Graphics.Draw 6.7, Graphics.Draw.draw_and_resource_release 6.2, Vulkan.Dispatch 4.6, VideoOut.Flip 4.6, Driver.Dispatch.decode_key_device_setup 4.3, Resources.Complete 4.3, Vulkan.Dispatch.shader_resources 3.4 **Longest waits** - Driver.Packet.rendering_wait (queue worker 0x0) 6.7 ms at 1092 ms, present 442 - Driver.Present.gpu_mutex_wait (presenter) 6.2 ms at 274 ms, present 410 - Driver.Packet.rendering_wait (queue worker 0x0) 4.2 ms at 1476 ms, present 457 - Driver.Packet.rendering_wait (queue worker 0x0) 4.0 ms at 2088 ms, present 483 - Driver.Present.gpu_mutex_wait (presenter) 2.8 ms at 3894 ms, present 554 - GpuMutex.wait.label (draw committer) 2.0 ms at 3202 ms, present 528 - GpuMutex.wait.flush (draw committer) 1.7 ms at 3848 ms, present 552 - GpuMutex.wait.dispatch (queue worker 0x0) 1.6 ms at 3980 ms, present 556 - Driver.WorkerWait (queue worker 0x0) 1.4 ms at 1801 ms, present 470 - Driver.WorkerWait (queue worker 0x0) 1.4 ms at 2656 ms, present 506 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 793: 1.3 ms at 2429 ms, present 496: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.8, Recorder.Submit (draw committer) 0.0, Graphics.Draw.validate (draw committer) 0.0 - batch 1434: 1.2 ms at 4367 ms, present 570: GPU no ranges; recorded by GpuMutex.wait.flush (draw committer) 1.3, Graphics.Draw (draw committer) 1.3, Graphics.Draw.draw_and_resource_release (draw committer) 1.3 - batch 1093: 1.1 ms at 3282 ms, present 531: GPU no ranges; recorded by Graphics.Draw (draw committer) 2.4, Graphics.Draw.draw_and_resource_release (draw committer) 2.3, Resources.Complete (draw committer) 0.9, Resources.Prepare (draw committer) 0.2 - batch 636: 1.0 ms at 1947 ms, present 476: GPU no ranges; recorded by Graphics.Draw (draw committer) 13.4, Graphics.Draw.draw_and_resource_release (draw committer) 13.3, Resources.Complete (draw committer) 11.4, Resources.Prepare (draw committer) 0.2 - batch 698: 1.0 ms at 2133 ms, present 484: GPU no ranges; recorded by Graphics.Draw (draw committer) 2.0, Graphics.Draw.draw_and_resource_release (draw committer) 1.9, Resources.Complete (draw committer) 0.1, Recorder.Submit (draw committer) 0.0 </details> <details><summary>tools/trace_digest.py, this branch</summary> **frames 400:180** from present 400: 180 presents, frame p50 16.7 / p90 16.9 / p99 17.1 / max 70.7 ms, GPU busy 1.1 ms per present NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit e21aa4cabddf, dropped: no ```json {"commit":"e21aa4cabddf","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_FRAMES":"400:180"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03743","title":"Soul Hackers 2","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"frames 400:180","first_present":400,"ms":3052.999},"presents":180,"frame_ms":{"p50":16.684,"p90":16.858,"p99":17.096,"max":70.738},"gpu_busy_ms_per_present":1.13,"worker_busy_pct":{"queue worker 0x0":37.443},"top_phases_ms_per_frame":{"VideoOut.Flip":16.17,"VideoOut.Flip.vblank_wait":15.224,"Driver.Packet":6.349,"Graphics.Draw":3.92,"Graphics.Draw.draw_and_resource_release":3.668,"Driver.Packet.draw":2.262,"Driver.Draw":2.252,"Driver.Packet.dispatch":2.245},"trace_dropped":false,"trace":"aps5-trace-e21aa4cabddf-23548.json.gz"} ``` **Slowest frames** (largest slices inside each, inclusive) - present 448: 70.7 ms at 801 ms: Vulkan.GraphicsPipelinePrebuild (shader prepare) 129.1, Vulkan.GraphicsPipeline (shader prepare) 129.0, Vulkan.GraphicsPipelineLibrary (shader prepare) 129.0, Driver.Packet (queue worker 0x0) 70.2 - present 442: 17.1 ms at 701 ms: VideoOut.Flip (presenter) 17.0, VideoOut.Flip.vblank_wait (presenter) 15.7, Driver.WorkerWait (queue worker 0x0) 10.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 10.2 - present 414: 17.0 ms at 233 ms: VideoOut.Flip (presenter) 16.7, VideoOut.Flip.vblank_wait (presenter) 15.8, Driver.WorkerWait (queue worker 0x0) 11.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 11.4 - present 571: 17.0 ms at 2903 ms: VideoOut.Flip (presenter) 16.8, VideoOut.Flip.vblank_wait (presenter) 15.9, Driver.WorkerWait (queue worker 0x0) 11.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 11.4 - present 534: 17.0 ms at 2285 ms: VideoOut.Flip (presenter) 16.7, VideoOut.Flip.vblank_wait (presenter) 16.0, Driver.WorkerWait (queue worker 0x0) 10.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 10.8 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | queue worker 0x0 | 5.9 (35 %) | 10.5 (62 %) | 0.6 | 1.7 | Driver.Packet 5.9 | | draw committer | 4.1 (24 %) | 0.5 (3 %) | 12.3 | 0.4 | Graphics.Draw 3.9, Vulkan.DrawFromRecipe 0.1 | | presenter | 1.0 (6 %) | 15.3 (90 %) | 0.7 | 0.1 | VideoOut.Flip 16.2, Driver.Present 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 16.9 | 0.0 | Shader.PrepareArtifact 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.1 (1 %) | 0.0 (0 %) | 16.9 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.1 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.4 (2 %) | 0.0 (0 %) | 16.6 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.4 | | shader prepare | 0.4 (3 %) | 0.0 (0 %) | 16.5 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.4 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | shader prepare | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Vulkan.GraphicsPipelinePrebuild 0.0 | | title | 0.6 (4 %) | 0.1 (0 %) | 16.3 | 0.3 | Recorder.Sync 0.5, Shader.ResolveAbi 0.1 | | title | 0.0 (0 %) | 0.0 (0 %) | 17.0 | 0.0 | Shader.Register 0.0 | | gpu | 1.1 (7 %) | 0.0 (0 %) | 15.8 | 0.0 | batch 1.1 | **Largest slices** (ms per frame, inclusive, all threads): VideoOut.Flip 16.2, VideoOut.Flip.vblank_wait 15.2, Driver.WorkerWait 10.5, Driver.WorkerWait.idle_and_completion_poll 10.5, Driver.Packet 5.9, Graphics.Draw 3.9, Graphics.Draw.draw_and_resource_release 3.6, Driver.Packet.dispatch 2.2, Driver.Packet.draw 2.1, Driver.Draw 2.1 **Longest waits** - Driver.WorkerWait (queue worker 0x0) 31.3 ms at 767 ms, present 445 - Driver.WorkerWait (queue worker 0x0) 21.5 ms at 718 ms, present 443 - VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2286 ms, present 534 - VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2403 ms, present 541 - VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2186 ms, present 528 - VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 2153 ms, present 526 - VideoOut.Flip.vblank_wait (presenter) 16.0 ms at 635 ms, present 438 - VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 2904 ms, present 571 - VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 2136 ms, present 525 - VideoOut.Flip.vblank_wait (presenter) 15.9 ms at 1986 ms, present 516 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 640: 1.8 ms at 1594 ms, present 492: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.3, Graphics.Draw.draw_and_resource_release (draw committer) 1.2, Graphics.Draw.validate (draw committer) 0.1, Recorder.Submit (draw committer) 0.0 - batch 382: 1.6 ms at 993 ms, present 456: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.9, Resources.Complete (draw committer) 0.5, Resources.Prepare (draw committer) 0.1 - batch 833: 1.6 ms at 2027 ms, present 518: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.9, Resources.Complete (draw committer) 0.2, Resources.Prepare (draw committer) 0.2 - batch 1213: 1.6 ms at 3029 ms, present 578: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.6, Graphics.Draw.draw_and_resource_release (draw committer) 1.5, Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1 - batch 398: 1.6 ms at 1027 ms, present 458: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.2, Graphics.Draw.draw_and_resource_release (draw committer) 1.2, Vulkan.DrawFromRecipe (draw committer) 0.3, Graphics.DrawWithRecipe (draw committer) 0.3 </details> Where the time went before the change (timers inside `evict`, 10 s window, light scene): total 3,340 ms, `blank()` 2,979 ms, VirtualProtect 74 ms, views.erase 113 ms, copy of written pages 31 ms; 1,029,031 pages scanned, 26,670 written. Scanning the same pages a second time took 181 ms, and an SSE2 `blank()` changed nothing, so the cost is the first-touch faults. With the change: mutations holding the registry mutex 7.1 s -> 1.5 s per 10 s, lookups waiting on it 4.4 s -> 0.47 s, `evict` 0.53 s per 10 s. The heavy scene later in the game is GPU-bound and I see no difference there. Tests: `windows_mappings_release` passes on the rebased branch (`CheckTouchedPagesAnyOrder`, `CheckEvictKeepsWrittenPages`, which fails if `Run::reset` handling or the `markImported` call is removed). ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (no AGC, shader recompiler or VideoOut change) - [x] AI-assisted: yes. Written with AI assistance and reviewed by me.
MarcZX10 commented 2026-10-28 04:00:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T04:00:59Z.

Review: CHANGES_REQUESTED


I found a correctness risk in the write-watch filter: GetWriteWatch returns an array of page addresses, but the Windows API documentation does not promise that the addresses are sorted. evict advances nextDirty monotonically as if they are ascending. If the array is in another order, a page that was written can be skipped, so its contents are not saved and can be lost on eviction. Please sort the returned addresses (or use an order-independent page mark structure) and add a regression that supplies addresses out of order.

The host-import test also does not demonstrate that Run::imported disables filtering: as the PR notes, its test writes through the CPU-mapped run, which is itself visible to write watch. Please add a test where the bytes change through a path that write watch cannot see, or otherwise isolate that guard.

The current hosted Conventions check fails with 14 findings: explanatory comments were added in WindowsMappings.hpp and WindowsMappingsRelease.cpp, and the PR description omits the required ### What, ### Tested and ### Checklist template headings. Please remove or relocate those comments according to repository rules and restore the template. The perf label also requires paired aps5-summary.jsonl lines, attached traces and tools/trace_digest.py output. The current tables are not those artifacts, and the description says the scene windows are not paired; please provide same-machine captures of the same title and scene on current main and this head before claiming the measured improvement.

Finally, this branch is based on 439d03d, 33 upstream commits behind current main. CONTRIBUTING.md requires branches to be based on and kept up to date with main; please rebase and rerun the focused Windows mapping tests and checks after addressing the above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677635434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12227#pullrequestreview-5677635434). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T04:00:59Z. **Review:** CHANGES_REQUESTED --- I found a correctness risk in the write-watch filter: `GetWriteWatch` returns an array of page addresses, but the Windows API documentation does not promise that the addresses are sorted. `evict` advances `nextDirty` monotonically as if they are ascending. If the array is in another order, a page that was written can be skipped, so its contents are not saved and can be lost on eviction. Please sort the returned addresses (or use an order-independent page mark structure) and add a regression that supplies addresses out of order. The host-import test also does not demonstrate that `Run::imported` disables filtering: as the PR notes, its test writes through the CPU-mapped run, which is itself visible to write watch. Please add a test where the bytes change through a path that write watch cannot see, or otherwise isolate that guard. The current hosted Conventions check fails with 14 findings: explanatory comments were added in `WindowsMappings.hpp` and `WindowsMappingsRelease.cpp`, and the PR description omits the required `### What`, `### Tested` and `### Checklist` template headings. Please remove or relocate those comments according to repository rules and restore the template. The `perf` label also requires paired `aps5-summary.jsonl` lines, attached traces and `tools/trace_digest.py` output. The current tables are not those artifacts, and the description says the scene windows are not paired; please provide same-machine captures of the same title and scene on current `main` and this head before claiming the measured improvement. Finally, this branch is based on `439d03d`, 33 upstream commits behind current `main`. `CONTRIBUTING.md` requires branches to be based on and kept up to date with `main`; please rebase and rerun the focused Windows mapping tests and checks after addressing the above.
MarcZX10 commented 2026-10-28 04:08:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T04:08:10Z.

Review: CHANGES_REQUESTED


I rechecked the new head bdd5dc8bbfd5322d8d7e5249a6db586467289e20. The branch is now based on 061cdb66b0; comments/template issues from my prior review are resolved, and current hosted Conventions passes. The implementation and tests still have these blockers:

  1. GetWriteWatch results are consumed as if sorted: nextDirty only advances. The API does not promise address order. An out-of-order list can cause a written page to be skipped and its contents lost on eviction. Please make the membership check order-independent and add an unsorted-list regression.
  2. The host-import test still writes base[12 * step + 7], within the watched resident range. That write is visible to write-watch, so this test would continue passing if markImported were removed. Please exercise the import path with a write through a separate alias or another path that write-watch cannot observe, and show the filter falls back in that case.
  3. The perf report is still incomplete under CONTRIBUTING and the performance label bot: the description says the scene intervals are not paired and that the first_present values differ, no traces are attached, and there is no trace_digest.py output. Please provide compliant same-machine/same-scene captures on main and this change, with both traces and digests, or remove the performance claim/label through the repository’s normal process.

The reported focused Windows tests are useful, but hosted Windows is still running; Linux and specialized jobs are skipped. I independently ran git diff --check and python3 tools/check_conventions.py --base refs/review/main successfully. The current-main merge preview is clean, and the seven commits since the branch base do not touch the changed files. I’m keeping changes requested because of the correctness and required performance-evidence gaps above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677678135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12227#pullrequestreview-5677678135). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T04:08:10Z. **Review:** CHANGES_REQUESTED --- I rechecked the new head `bdd5dc8bbfd5322d8d7e5249a6db586467289e20`. The branch is now based on `061cdb66b0`; comments/template issues from my prior review are resolved, and current hosted Conventions passes. The implementation and tests still have these blockers: 1. `GetWriteWatch` results are consumed as if sorted: `nextDirty` only advances. The API does not promise address order. An out-of-order list can cause a written page to be skipped and its contents lost on eviction. Please make the membership check order-independent and add an unsorted-list regression. 2. The host-import test still writes `base[12 * step + 7]`, within the watched resident range. That write is visible to write-watch, so this test would continue passing if `markImported` were removed. Please exercise the import path with a write through a separate alias or another path that write-watch cannot observe, and show the filter falls back in that case. 3. The `perf` report is still incomplete under CONTRIBUTING and the performance label bot: the description says the scene intervals are not paired and that the `first_present` values differ, no traces are attached, and there is no `trace_digest.py` output. Please provide compliant same-machine/same-scene captures on main and this change, with both traces and digests, or remove the performance claim/label through the repository’s normal process. The reported focused Windows tests are useful, but hosted Windows is still running; Linux and specialized jobs are skipped. I independently ran `git diff --check` and `python3 tools/check_conventions.py --base refs/review/main` successfully. The current-main merge preview is clean, and the seven commits since the branch base do not touch the changed files. I’m keeping changes requested because of the correctness and required performance-evidence gaps above.
MarcZX10 commented 2026-10-28 09:19:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T09:19:47Z.

Review: CHANGES_REQUESTED


I rechecked the updated performance material against the current PR description and branch. The correctness fixes for unordered GetWriteWatch results and the reset/import fallback now have regressions, and the attached traces/digests in the comments are useful. Two required items still prevent approval:

  1. The PR description itself still contains the old, contradictory report: it says the capture windows were not paired and ends with “No traces are attached” / no trace_digest.py output, while the later comments attach frame-window traces. The performance rule requires the paired aps5-summary.jsonl lines, traces and digest in the PR report. Please consolidate the actual evidence into the description and remove the stale claim.
  2. Those new captures compare main b4b0c220a98c with this head, while current main has advanced to a444a18d93640c49a5504758b67b1ed0a553cc73; this branch has not changed since d9bfa99d7f. Please rebase/update to current main, rerun the focused Windows mapping tests, and capture the same title/scene/machine on the updated main and rebased head before claiming the performance result.

The focused Windows mapping tests and hosted matrix reported for d9bfa99d7f pass, but they do not cover the latest base or repair the report's stale description. I am keeping changes requested pending those items.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680322468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12227#pullrequestreview-5680322468). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T09:19:47Z. **Review:** CHANGES_REQUESTED --- I rechecked the updated performance material against the current PR description and branch. The correctness fixes for unordered `GetWriteWatch` results and the reset/import fallback now have regressions, and the attached traces/digests in the comments are useful. Two required items still prevent approval: 1. The PR description itself still contains the old, contradictory report: it says the capture windows were not paired and ends with “No traces are attached” / no `trace_digest.py` output, while the later comments attach frame-window traces. The performance rule requires the paired `aps5-summary.jsonl` lines, traces and digest in the PR report. Please consolidate the actual evidence into the description and remove the stale claim. 2. Those new captures compare `main` `b4b0c220a98c` with this head, while current `main` has advanced to `a444a18d93640c49a5504758b67b1ed0a553cc73`; this branch has not changed since `d9bfa99d7f`. Please rebase/update to current `main`, rerun the focused Windows mapping tests, and capture the same title/scene/machine on the updated `main` and rebased head before claiming the performance result. The focused Windows mapping tests and hosted matrix reported for `d9bfa99d7f` pass, but they do not cover the latest base or repair the report's stale description. I am keeping changes requested pending those items.
MarcZX10 commented 2026-10-29 10:11:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:11:17Z.

Review: APPROVED


Rechecked exact head e21aa4cabddf. The change now treats GetWriteWatch results as an unordered set, and only filters pages for a run whose write-watch state is still complete; reset, import, and API-failure cases use the full-scan fallback. The added tests cover scrambled address order, eviction retention, cleared write-watch on imported memory, and reset behavior. Current main has a clean merge preview and no files changed on both sides since the capture base. Current-main conventions and git diff --check pass; the hosted Windows and policy checks pass, while Linux and specialized jobs are skipped.

The PR description now contains the paired main/change summaries, same-title/same-session capture details, performance comparison, both digests and attached traces. The reported 180-frame comparison is on main 2227f1366188 and the rebased PR head e21aa4cabddf; the PR files have not changed on current main since that base. I did not independently rerun the Windows tests or capture. The earlier correctness, report-format and base-sync blockers are addressed; approved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696029380 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12227#pullrequestreview-5696029380). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T10:11:17Z. **Review:** APPROVED --- Rechecked exact head `e21aa4cabddf`. The change now treats `GetWriteWatch` results as an unordered set, and only filters pages for a run whose write-watch state is still complete; reset, import, and API-failure cases use the full-scan fallback. The added tests cover scrambled address order, eviction retention, cleared write-watch on imported memory, and reset behavior. Current `main` has a clean merge preview and no files changed on both sides since the capture base. Current-main conventions and `git diff --check` pass; the hosted Windows and policy checks pass, while Linux and specialized jobs are skipped. The PR description now contains the paired `main`/change summaries, same-title/same-session capture details, performance comparison, both digests and attached traces. The reported 180-frame comparison is on `main` `2227f1366188` and the rebased PR head `e21aa4cabddf`; the PR files have not changed on current main since that base. I did not independently rerun the Windows tests or capture. The earlier correctness, report-format and base-sync blockers are addressed; approved.
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!12227
No description provided.