perf(shader): allocate a program's instruction list nodes from a pool #11967
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11967"
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 milescoviello on 2026-10-27T14:06:35Z.
What
Performance evidence: this is a CPU-only change to shader compilation, and the SPIR-V is byte-identical. oneandonlydean accepted paired replay timings for this class of change instead of title captures (#9132, #9198, #11719); the timings and a profile are below.
Every
IrBlockkeeps its instructions in astd::list<IrValue*>, so each instruction a pass appends, inserts or erases is oneoperator new/deleteof a 24-byte list node. The nodes end up scattered across the heap. Passes walk these lists over and over,ValidateProgram, dead code elimination, the masked-select and resource passes among them, and the node loads are where much of their time goes. In a profile of the shader replay, the hottest instructions inValidateProgramwere the loads ofnode->valuewhile walking a block.This keeps each program's list nodes in a pool owned by the program.
IrBlockholds astd::pmr::list<IrValue*>(IrInstructionList).IrProgram::CreateBlockgives each block a sharedstd::pmr::unsynchronized_pool_resource, so a block's nodes are allocated next to each other and freed into the pool's free lists instead of the heap.Measured with the shader replay over the 152 Crimson Desert (PPSA25286) pipeline requests in
--preparemode, the same corpus as #11798, #11820 and #11719:maineece5da035Together with #11798 and #11820, the replay takes 48.2 % less time than on
main. Max RSS grows by about 1 MB (+0.5 %), because the pool keeps freed nodes for reuse until the program is destroyed.Where the time goes, from
perf record -F 499of one replay of the same corpus on each side (samples, not percentages):mainmalloc,freeand their internals)ValidateProgramConstantFolder::FoldIrValue::HasUsesIrValue::ParentRemoveRegisterStatePseudosDeadCodeEliminator::RemoveIdentitiesThe allocator saves about 1,100 samples. The passes that walk the instruction lists save more again, because their nodes now sit together in memory instead of wherever
mallocput them.The SPIR-V is byte-identical to
main's: all 65 modules from the Crimson Desert requests and all 302 from MXGP 26's (PPSA30839) dump. The replay logs match too. This only changes where list nodes live; instruction order, iteration and erase semantics are those ofstd::list.How
IrBlock.hpp:using IrInstructionList = std::pmr::list<IrValue*>.Instructions()returns it. A new constructor takes the shared resource. The resource'sshared_ptris declared before the list, so it outlives the list's nodes.IrBlock(id)without a resource keeps the default (new/delete) resource, which is what blocks made outside a program use (resource plans, the disk cache, tests).IrProgram: oneshared_ptr<std::pmr::memory_resource>, created on the firstCreateBlock. Each block holds a reference, so the pool lives until the last block is gone. That keeps the implicit move constructor and move assignment correct: a moved-from or reassigned program's blocks still own their pool, and nothing needs ordering.unsynchronized_pool_resourceisn't thread-safe. A program's blocks are only changed by the thread compiling it, as they already must be forstd::list. No pass shares a program's lists across threads.auto&and iterators, and no code splices or swaps instruction lists between blocks, whichpmrlists with different resources wouldn't allow.std::pmr::unsynchronized_pool_resourceneeds a libc++ with<memory_resource>(macOS 14 deployment target or newer). The repository sets no deployment target, and macOS CI builds only the relinker.Tested
Linux (Ubuntu 26.04, GCC 15.2):
ctest3 runs: all 75 entries pass in every run at this head (007c0bf37e).agc_ir_reclaim,agc_shader_memoryandagc_validate_program, 3 runs: all pass, with no AddressSanitizer or LeakSanitizer report.mainand on9f01a1aedf(this change plus an#include <memory_resource>inIrProgram.hpp, since dropped becauseIrBlock.hppincludes it): 26 of 26 pass in all 3 runs on both sides.Title captures, Black Ops II with a cold recompiler cache, 3 interleaved runs per side, each side with #9656 (details and summary lines). Prepared artifacts take about 12 % less time on the prepare workers and about 14 % less on the title thread. The worst frame, a synchronous shader-preparation hitch at boot, is about 120 ms shorter in all three pairs. No frame-rate claim.
Timing method: release
agc_shader_replaybuilds (SPIR-V Tools off, as users build) of each side,perf stat -e task-clockand/usr/bin/timemax RSS. 10 rounds of the five builds in a rotating order,ANYPS5_NO_SHADER_CACHE=1, nothing else running.Title captures: Super Meat Boy 3D,
main9af563f33d+ #11580 (608dd76843) against the same + this PR (94d925a0c8), 3 interleaved rounds, recompiler cache off.Shader.PrepareArtifactworker time is 23,694 ms → 13,377 ms (-43.5 %, lower in 3 of 3); over each run's first 400 worker artifacts 9,331 ms → 5,841 ms (-37.4 %) and over the first 350 title-thread artifacts 5,789 ms → 3,860 ms (-33.3 %), 3 of 3 each (table and traces). Round 2's summary lines: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