perf(agc): query unit shadows without copying the overlap list #856
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/856"
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 meh7an on 2026-10-06T09:59:25Z.
What
AnyShadowedOverlapsis asked on every guest access the flush hook sees and on several draw and copy paths. It collected the overlapping shadows into astd::vector<std::shared_ptr<UnitShadow>>(an allocation, and a reference count increment and decrement per shadow) only to read them under the registry lock it already holds. It now visits them in place throughanyOverlapping, whichoverlapping()also uses for the callers that need the list.Tested
Windows 11, MinGW GCC 15.2, RTX 2080 Ti. This branch builds, and the 165 agc driver, recompiler and execution test targets pass with it stacked on the other changes I'm sending.
Measured alone on Sonic Origins Plus's heaviest menu page (about 1,650 draws per frame), as asked. The base is
mainat this PR's base (5895ea72) plus the commits my branch needs to boot this title and to sample it (a launcher script, the title's boot fixes, the process sampler; none of them are in this PR), against the same base with this commit on top. Three interleaved rounds, each the median of six FPS readings:Ahead in every round, though the gap is larger than the profile supports, so the profile is the better figure: over two 15 s profiles per side,
AnyShadowedOverlapstook 39 of 5,119 AGC worker samples on the base and 24 of 4,920 with this PR. The 16 samples that went are the list building inoverlappingand its heap allocation; what is left is the registry lock. That is about 0.3% of the worker, roughly 0.3 ms per frame.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T21:21:07Z.
Thanks.
anyOverlappingvisits the same shadows in the same order, andAnyShadowedOverlapsreturns at the same live unit as before, so the result is unchanged.One thing before it can go in. Performance PRs need before/after numbers for the change itself (the owner asked for this on #218). The 48.0 to 43.6 ms figure is for 15 changes together. Could you measure
mainagainstmainplus this PR alone on the same page? The mean frame time over a few runs is enough, or theAnyShadowedOverlapsshare of the profile.Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-07T17:02:29Z.
Measured it alone and put the numbers in the description: the overlap list building and its allocation (16 of 5,119 AGC worker samples, about 0.3%) are gone, and what is left under
AnyShadowedOverlapsis the registry lock. The FPS rounds were ahead each time, but the profile's 0.3 ms per frame is the figure to go by.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T01:56:32Z.
Review: COMMENTED
Built and ran it — external PRs get no CI here.
Linux (CachyOS, GCC, Release), NVIDIA RTX 3080 Ti:
The rewrite is behaviour-preserving.
AnyShadowedOverlapsreturns true on the first live unit, which is exactly what the old loop did — the old body pushed into a vector and then scanned it, with no side effect after the push, so the early exit cannot change which unit is found. The guard (end <= address || byBase.empty()) and theupper_bound/--itwalk are unchanged, so the search space is identical.Two details that make the equivalence complete rather than approximate:
overlapping()wrapper passes a visitor that always returnsfalse, so it still walks the whole range inbyBaseorder and builds the list in the same order for callers that need it. Nothing that consumes the vector sees a different ordering.AnyShadowedOverlaps(std::span<...>)) delegates to the address overload in a loop and short-circuits on the first true, so it inherits the change without modification — I checked it rather than assumed it, since that was the one place the treatment could have been left half-applied.The win is the
shared_ptrcopies. Naming it explicitly because it is the more interesting half: the old path copied ashared_ptrper overlapping shadow, and each copy is an atomic increment plus, on destruction, a decrement. Removing the vector removes those atomics per query, not just a small allocation. That is a real cost in a path that runs per guest store.What I could not do: measure it. There is no benchmark here that isolates
AnyShadowedOverlaps, so what I have is equivalence and no regression, not a number — I would rather say that than quote a timing I did not take.This is a comment, not an approval — I have no merge rights here.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:59:49Z.
Checked the diff (same guard and
upper_boundwalk, early exit at the first live unit as before,overlapping()keeps order and full walk), build + ctest on top of current main (535/535) and green CI on the head. The isolated before/after numbers requested above are in the description; merging.