perf(libc): start the guest allocation overlap queries at the range that touches the address #6321
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6321"
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 mariuszkreft on 2026-10-15T11:31:38Z.
What
GuestAllocationsOverlapsandGuestAllocationsRequireAvailablewalked the whole guestallocation range registry from
begin(), so every mapping-sized query paid for everyregistration below the queried address. #4634's samples put the
sceKernelBatchMap2threads' time in exactly these two calls, reached from
DoMapDirect, with ~35,000 live64 KiB direct mappings in the registry.
Both now start at
firstRangeTouching(address): the first range at or after the address,or the one before it when that one reaches into the address. The step back is the point — a
query landing inside a registered range is the overlap these functions exist to report, and
a scan that starts at
lower_boundalone misses it.GuestAllocationsAcquirealso reservesthe registry size before filling its vector.
Acquireis unchanged in behaviour: the vector is still rebuilt when its weak_ptr cachewas reset, which a mutation does. Making that cheaper needs the pin test to stop relying
on
use_count(), which is what #1324 is about.Tested
Linux, Ubuntu 24.04, GCC 13.3, Release, full build (
-DBUILD_TESTING=ON) on this branchwip/gta-v-4634-registry-scanoverorigin/main:ctest --test-dir build --output-on-failure -j 12→ 1233/1234 passed.The single failure,
agc_pending_key_stores, reproduces on cleanorigin/mainon thishost: it needs host write protection, and the NVIDIA driver here reports
host imports resolve write protection: no (0 of 4 scratch pages written).guest_memory_testspasses, including the added case that pins the interior-addresscase: with a scan that starts at
lower_boundalone the suite aborts atGuestMemory.cpp:2009.python3 tools/check_conventions.py --base origin/main→ all conventions checks passed.Measured on the same machine, the real translation unit, 35,000 registered 64 KiB ranges
and 20,000 probes mixed across range starts, interiors and gaps:
GuestAllocationsOverlaps×20,000GuestAllocationsRequireAvailable×20,000GuestAllocationsAcquire×2,000Identical results before and after: 4375 overlaps found, 4375 mappings refused.
No title was run. The win is measured on the registry with the title's range count,
which is the cost the profile attributes to these calls; it is not an end-to-end frame-rate
claim. #4634's own title runs belong to whoever owns that dump.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T12:30:34Z.
Independent Windows CPU validation of head
a52b7235b21834d0f8b5541ff2f3b8126f724c1dagainst PR base341613ab62b979e429daa1be5ac2fe524a737df6(AI-assisted).I compiled each version's complete, unchanged
GuestAllocations.cppwith its unchangedGuestAllocations.hpp(header identical between the two refs), plus an external synthetic probe. Windows 11 22631, Intel Core i7-8700, WinLibs GCC 15.2.0 r7,-std=c++20 -O3 -DNDEBUG -static -pthread; no LTO.Correctness: 177,125 deterministic scenarios per execution, zero mismatches on each of four executions (base, PR, PR, base). Registry sizes 0, 1, 32, 512, 4,096 and 16,384; non-overlapping ranges have 4/8/12/16 KiB lengths on a 32 KiB stride. For each size, 12,000 random valid queries (seed 6321) check both
OverlapsandRequireAvailableagainst a separate brute-force intersection oracle; additional one-byte boundary/interior/gap queries checkOverlaps. The registry is held under aMutation; fake addresses are registered, never dereferenced or OS-mapped.Timing: these are deliberately worst-position free queries beyond the last registration, excluding setup, mutations and exceptions. Five batches of 3,000 calls per function per registry size per execution; table is the median of ten batches per version, ns/call, base -> PR:
The growing-registry result supports the intended removal of a linear prefix scan on Windows too. Empty/single-range registries cost a few more nanoseconds, so this is not a universal speedup. The timing workload is synthetic, cache-warmed, free-only and near the end; it is not a representative frame workload or an FPS result.
Attached: probe source, reproducible Windows runner (set
CXXto your compiler), pinned source/header snapshots, machine/compiler flags, raw samples and hashes. No production edit or separate PR.Limits: no full emulator build, project CTest/GuestMemory suite, hardware GPU/title run, concurrency stress, OS mappings, zero-sized registrations, invalid-input validation, lease-acquire benchmark or composition with current main/other PRs tested. This independently validates the two overlap-query changes, not the whole PR or resolution of #4634 on a title.
windows-perf-pr6321.zip
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T13:24:33Z.
Minimal cleanup for the seven current Conventions failures on head
a52b7235b21834d0f8b5541ff2f3b8126f724c1d(AI-assisted).The patch removes only the four prose-comment lines before
firstRangeTouchingand the three before its regression. The non-comment C++ text is identical after whitespace normalization, checked with the repository's C++ tokenizer; no algorithm, test statement or new debt entry is added.I reproduced all seven
[comment]findings using the trustedtools/check_conventions.pyandnid_names.pyfrom main2e5dd5aa144af1bf90a214a6341bf3e1b4e6d47a, against a minimal isolated Git fixture containing the exact two files from the PR base and head. The same checker against the cleaned fixture exits 0:All conventions checks passed.This checks the affected file delta, not the complete upstream tree, PR template or hosted CI. No native tests/benchmarks were repeated for this comment-only change; my earlier CPU probe remains evidence only at its recorded head. No source-checkout edit, push to your branch or separate PR. The author still needs to apply the patch and rerun the hosted check.
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T18:19:46Z.
Tested on Linux x86-64 (Release build) at a52b7235b, which merges cleanly with main
03c4cb5e7:guest_memorypasses.tools/check_conventions.py --base mainstill reports the 7[comment]errors (GuestAllocations.cpp:358-361, GuestMemory.cpp:2333-2335), so the hosted check stays red until those comments go.The new test also passes on main, since main returns the same results, just slower. To show the speedup itself, here is a cost test modelled on
CheckMappingCostFollowsTheMappingCount. It times both queries against 1024 and 16384 registered ranges and requires the large case to cost at most 4x the small one:GuestAllocations.cpp: 0.027 s vs 0.97-1.02 s (about 35x), so it fails atRequire(large <= small * 4).The patch below also removes the 7 comments, so
git applyon the PR head should clear both.Patch against a52b7235b
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T23:04:15Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T20:25:26Z.
AI-assisted independent validation of a local refresh of this PR on main
252cbc29beac26811ad9338c22bcba336d7d2ebe(candidate0e448213e27e581a97e3031bb1215a4e0054b018).The attached
refresh.patchpreserves both original authors. Resolving theGuestMemory.cppconflict keeps both main's regular-file-mapping test and this PR's overlap regression. Main's current strongreadableLeasecache remains intact.libsandguest_memory_testsbuild;guest_memorypasses on main and candidate; conventions andgit diff --checkpass.PPSA05347, Record of Lodoss War: Deedlit in Wonder Labyrinth, forest sword/jump tutorial: 26.068 FPS main → 27.946 FPS candidate (+7.205% observed). Frame p50/p90/p99: main 36.525/46.630/59.935 ms; candidate 34.471/41.212/54.146 ms. Both reached the same tutorial location in the 190/240-second screenshots and exited cleanly.
Ryzen 9 7950X / RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9; trace resolution 3840×2160. One candidate-then-main pair, identical starting warm-cache clones, same scripted inputs, pipelined draws and DMA enabled on both, trace window
seconds 200:30. This is preliminary evidence, not a replicated or general speed claim. The current comparison tool flagswindow.first_present(9518 main / 9793 candidate); the fixed wall-clock capture interval, GPU/driver/OS/resolution and recorded environment match. No metadata was rewritten to bypass that check. Neither trace reports dropped events. Screenshot checks do not establish full-game correctness.Evidence archive includes both complete traces, original summary lines,
tools/trace_digest.py --jsonoutputs, comparison output, screenshots, launch protocols/cache manifest, focused test logs, and refresh patch. SHA-256:76946d0adae3437e3f349326bdba194de22c568640c8c17660a019a097b9298a.Main summary:
Candidate summary: