perf(agc): find a host import among the last ones found first #8896
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8896"
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 teepean on 2026-10-21T04:59:26Z.
What
HostImportForwalks the import map (std::map<std::uint64_t, HostImport>,upper_boundthen one step back) under the import mutex for every range it serves. On Stray (PPSA02100) that is every in-place vertex input and index buffer of every draw, and every label write, about 12,000 lookups per frame, nearly all of them for the same few buffers. In my stack-sample profile of the draw committer on a build where the committer bounds the frame,HostImportForwas 4.7 % of the committer's samples, almost all of it in the map walk.A lookup now first checks the last four imports a lookup found (
recentImportsinHostImports, under the same mutex), and walks the map only when none of them contains the range:epochbefore the entry leaves the map,ClearHostImportsclears the map and bumps it, and every insert changes the map's size. SorecentEpoch == epoch && recentSize == imports.size()means no entry was added or removed since they were found.importRunAtretires the imports a new run covers before inserting it. So the one import that contains the range is the map's answer.lastUseas the map hit did.APS5_NO_RECENT_IMPORTS=1looks every import up in the map (row added todocs/dev/ENVIRONMENT.md).Tested
Linux (CachyOS, kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release. Measured at 590a2b4747 on
main7e95bde794; the head is the same change rebased ontomain3fb6a126fa(only #7082's test line conflicted), and the tests below pass again on it.agc_host_import_retire_tests,RecentImportFollowsReplacement: a repeated lookup finds the same import, the heap grows, the grown run replaces the first import, and the next lookup of the first range must return the replacement. It passes with this change and fails against a copy whose cache ignores the epoch and size (it serves the retired import).VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, these pass with no VUIDs:agc_host_import_retire_tests,agc_host_import_sparse_tests,agc_driver_host_import_at_map_tests,agc_driver_host_import_teardown_tests,agc_driver_host_import_windows_testsandagc_driver_bda_device_tests.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchfound one overlap, #7082, which added its test at the same place inHostImportRetireHold.cpp'smain; it has since been merged, and the head is rebased over it. Of the pull requests it could not compare (they conflict withmain), #1324 and #4448 changeHostImportFor's lookup as well; whichever of these lands later needs a small rebase.Stray at the start of Dead City, stock
engine.ini, glibc, one run at a time, six rounds ofmain7e95bde794, this change and a second candidate, with this change andmainfirst or last in alternate rounds, and onlyAPS5_TRACE_SECONDS=185:20set:main7e95bde794Each cell is frame p50 / GPU busy per present / the draw committer's busy time per frame, in ms, from
tools/trace_digest.py. Left out:mainrun after its build, which spent the window in the menus compiling shaders;main5f7e30233erun I measured yesterday (1,196 ms, 99.6 %), and a plainmain7e95bde794run fell into it later the same night (962 ms), so it is not something this change introduces.On
main, Stray in this scene is bound by queue worker 0 (97-98 % busy), and the committer is busy about 48 ms of a ~167 ms frame. So the change can't show in the frame time here, and the committer's time stays within the spread between runs. It pays where the committer bounds the frame. On my local stack (showcase/stray-stack), where it is,HostImportForwas 4.7 % of the committer's samples, and this change was worth +2.6 % FPS there (17.48 to 17.93, four balanced rounds, all four won).Traces, summaries and digests: https://github.com/teepean/AnyPS5/releases/tag/perf-recent-host-imports-20261021 (every run's
aps5-summary.jsonlanddigest.md, and the traces of the median pair and of the 0.9 FPS run).Summary lines of the median runs
main7e95bde794:this change:
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 JJenkx on 2026-10-22T10:55:03Z.
AMD/Linux data point: neutral on a title that does far more host-import work than Stray, and holds no queue worker at saturation.
Setup
main3fb6a126faagainst this PR's head2d681c7cbe, clean builds.main, PR, PR,main.APS5_TRACE_SECONDS=200:30with 2097152 events; every trace reports dirty false and dropped false.mainthis scene is CPU-bound below its 60 FPS cap. It is dominated by map-time host-import attempts: about a million refused per run.mainmainThe two sides overlap:
main50.6–54.2 FPS against the PR's 51.6–53.9, with frame p50 18.1–18.5 ms on both. No change shows at this scene's run-to-run spread. The import counts vary between runs on both sides, including onemainrun with 3273 failed imports; they are listed for completeness, not attributed to the PR.AI-assisted: yes (Claude Code); results above were run on this machine.