perf: every guest malloc and free makes the next draw rebuild a lease over the whole allocation registry (Godot PS5, about 2.4 ms per draw) #26456
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 consolelogout on 2026-11-23T23:45:42Z.
Title and scene
Godot PS5 (PPSA99847, v0.2.10, content version 01.000.021) from https://github.com/Yahballon/PS5_Godot, SHA-256 checked against the release asset digest. Its built-in Pong, idle on the court after start, no pad input. Converted as in its bring-up thread (#24732):
relinker --windows --to-intel --registry --trap-sdk-syscall-stubsaftertools/unwrap_self.pyoneboot.binandsce_module/libc.prx.What is slow or what changed
Pong runs at about 28 fps (frame p50 35.6 ms) with the GPU busy 8.3 ms per present. The draw committer is the bound: 86 % busy,
Graphics.Draw19.9 ms per frame. #24732 reported 25 to 28 fps on another machine.Where the draw time goes. With
APS5_PROFILE_DRAW=1, per 10 s: about 3,100 draws; 780 are draw-recipe hits at 73 us, about 2,350 are template hits at 2,381 us. Of the draw phases,vertexis 2,686 ms andlookup2,748 ms.[rescache] revalidatereports 3,131 calls, 2,740 ms, all on the fast path.[recipe] drawreports 780 hits and 2,340 attaches with no pre-check misses.Stacks.
APS5_SAMPLE_COMMITTER, symbolized withtools/symbolize_samples.py --demangle: 58 % of the committer's samples are undercommitDraw, and by self time:refreshImports24 %;GuestAllocationsAcquire_nid_postfix20 %;std::_Rb_tree_increment9 %, underGuestAllocationsAcquire.Both come from two places on each draw:
vertexphase:prepareDrawInputs > InPlaceDrawInput > HostImportFor;lookupphase:resolveDrawResources > ShaderResources::Revalidate > revalidateFull > HostImportsReconciledUnchanged.Each takes a lease and calls
refreshImportswheneverGuestAllocationsGenerationmoved since the last refresh (importsStale,GuestBufferMemory.cpp:2991, and:8478).What moves the generation. I added a temporary counter around
generation.fetch_addinGuestAllocationsEndandGuestAllocationsInvalidate, keyed by return address, plus a count ofGuestAllocationsAcquirecalls that rebuilt the lease against those that reusedreadableLease. Per 10 s:GuestAllocationsEnd, 0 fromGuestAllocationsInvalidate;GuestHeapAllocate_nid_postfix24,364,ApplicationHeap.cppdefaultFree(GuestHeapFree_nid_postfix) 24,364,GuestHeapReallocate_nid_postfix9, and about 270 each from libkernelDoMapDirect,DoMunmapandsceKernelReleaseDirectMemory;So the title's own heap traffic, about 2,400 mallocs and 2,400 frees per second, each registered as a range (
GuestHeap.cpp,allocateandfreethrough aGuestAllocations::Mutation), moves the generation between almost every pair of draws. EachGuestAllocationsAcquirethen copies theshared_ptrof every readable range, up to about 156,000, into a new lease (readableLeaseis reset inGuestAllocationsBeginandGuestAllocationsEnd), andrefreshImportsdiffs that lease againststate.refreshedRanges(changedSpans) before it can tell nothing relevant changed.GuestHeapUsableSize_nid_postfixalso opens a mutation and bumps the generation, although it only reads.How much is at stake. As a measurement only, I let the heap's mutations skip the generation bump (a thread-local flag set in the
GuestHeap*functions and read inGuestAllocationsEnd). This is not safe: heap blocks can be host-imported, sincecontinuesRunanddesiredRundo not look atgpu. Same build, 60 s each:lookupms per 10 svertexms per 10 smainlookupdrops to almost nothing.vertexstays high becauseHostImportForstill takes a lease for every vertex range that has no import yet, and the lease is still rebuilt after every heap mutation, even when the generation does not move.Related. #11795 measures a whole-registry pass per address-space rebuild in RESIDENT EVIL requiem (there from import epoch moves). #6453 is about whole-registry leases on munmap/mprotect.
Possible directions, for whoever knows this path:
GuestAllocationsEndalready has the changed spans (state->changed, passed to the invalidator). A bounded log of(generation, span)would letimportsStaleandrefreshImportsadvancerefreshedGenerationwithout a lease when no changed span touches, or is next to, an import, a failed or refused run, a growth run or a pending import.refreshedRangescould stay as it is, so a later full diff still covers the skipped changes.HostImportFormisses for ranges already known not to be importable without a new lease, until a change touches them.GuestAllocationsAcquirecheaper after a heap mutation, or keep heap blocks out of the readable lease where no import can use them.GuestHeapUsableSizeread without a mutation.I can work on one of these if you say which direction you'd accept.
Summary lines
(
phase_totals_ms,owned_draw_countsandgraphics_tracktrimmed here; the full line is in the attachedaps5-summary.jsonl.)Traces
aps5-trace-f4c9a67f581b-24740.json.gz(attached).Digest
Worker stacks
committer.collapsed.txtfromAPS5_SAMPLE_COMMITTER(attached; a separate 45 s run withAPS5_PROFILE_DRAW=1).Capture
AI-assisted: yes