perf(libc): remember readable image pages in the Windows unwinder #20735
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20735"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by slopezjur on 2026-11-15T14:13:07Z.
What
On Windows the unwinder resolves each personality routine through
ResolveImport, which checks withVirtualQuerythat the import thunk and its slot are readable. That is two system calls per resolved address, three addresses per foreign frame and one per personality call, for every frame of both unwind phases. In a title that throws often inside host libraries this was most of the cost of a throw.Readablenow remembers a page thatVirtualQueryreported readable when the page lies inside a loaded image, keyed by the image identityIndexFramesalready uses (base, time stamp, checksum, image size) plus the page. Later unwinds through the same image make no system call.VirtualProtectto no access on such a page would not be noticed.New Windows test
unwind_import_queries: it replaces libc'sVirtualQueryimport with a counter, throws and catches twice to warm up, then requires that 256 more throws make no query.Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release.
Tests matching
unwind|except|demangle|dynamic_cast|bad_optional|bad_any|filesystem_error|message_destructor|standard_error|terminate|rethrow|nested|typeinfo|cxa(231, including the driver image table tests), onmain6cd3f92560and on this change based on it:mainwith the new test addedunwind_import_queries: "repeated unwinds through one image do not query its pages again")The branch was then rebased onto
main178944e753, which does not touch the exception sources; the tests were not run again after the rebase. Not tested on Linux or macOS (the changed code is inside#ifdef _WIN32).Ghost of Yōtei
PPSA26344 v02.002.000, DRS 1080p patch, Digital Deluxe "Press X" screen from a fresh save, warm shader cache, NVIDIA GeForce RTX 4080 SUPER (driver 621.14). Both rows use one build of
maincc4e13836fmerged with #20017, #20018 and #20519 (mergea13e0362e7,APS5_BINDLESS_IMAGES=1 APS5_BINDLESS_LAZY=1); onlylibc.prxdiffers, built from the same merge with and without this commit. The digests print commita13e0362e720for both rows because that stamp comes from the driver.Without profiling, four 330 s runs in the order base, change, base, change, presents between 180 s and 320 s:
mainWith
APS5_PROFILE_DRAW=1andAPS5_TRACE_SECONDS=270:5, one run each:mainThe throws in this scene come from the per-draw image table path (
DecodeTextureResourceon invalid table elements); this PR makes each throw cheaper and does not remove them. A first traced run with this PR ended at 66 s with an access violation in the title's own code during the load; the rerun and the two untraced runs were clean. The load crash also happens on this title without this PR, and I did not investigate this occurrence. Not measured: other titles, other GPUs.tools/trace_digest.py:mainlibcseconds 270:5 from present 1248: 12 presents, frame p50 472.8 / p90 487.0 / p99 488.2 / max 488.2 ms, GPU busy 198.0 ms per present
NVIDIA GeForce RTX 4080 SUPER, NVIDIA 621.14, Windows 10.0.26300, 3840x2160, commit a13e0362e720, dropped: no
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 2047.0, Driver.WorkerWait.idle_and_completion_poll 2047.0, Driver.Packet 1780.6, Driver.Packet.memory_wait 1020.6, Driver.Packet.dispatch 684.5, Driver.Dispatch 522.9, batch 183.5, Vulkan.Dispatch 164.9, Driver.Dispatch.capture_resources 121.3, Vulkan.Dispatch.shader_resources 115.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py: this PRseconds 270:5 from present 1309: 13 presents, frame p50 385.4 / p90 422.4 / p99 489.1 / max 489.1 ms, GPU busy 187.4 ms per present
NVIDIA GeForce RTX 4080 SUPER, NVIDIA 621.14, Windows 10.0.26300, 3840x2160, commit a13e0362e720, dropped: no
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1782.0, Driver.WorkerWait.idle_and_completion_poll 1782.0, Driver.Packet 1662.4, Driver.Packet.memory_wait 949.8, Driver.Packet.dispatch 633.3, Driver.Dispatch 479.4, batch 186.4, Driver.Dispatch.capture_resources 127.9, Vulkan.Dispatch 96.5, Driver.Dispatch.lookup_cache 87.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T14:16:37Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed implementation and test sources were read, but checks were not run in this review.
What I ran
Head:
40b179dd6cab62299e013db1d59f19f860749710. No commands or tests were run. Read the prepared description, commits, manifest, diff, and all three changed files; no changed files were excluded.Results
Findings
Blocking
None found in the code read.
Non-blocking
None.
Not verified
I did not run the Windows test suite or reproduce the reported performance captures. Linux and macOS behavior was not tested; the changed code is guarded by
_WIN32. The description reports tests on Windows 11 with WinLibs GCC 15.2.0 r7 and performance captures on Windows with an RTX 4080 SUPER; those results were not run or independently confirmed here.To get this to a good state
Nothing is required. Optional: run the Windows
unwind_import_queriestest on this head and attach the result.