perf: SuperTuxKart (PPSA69421) race at ~10 FPS on macOS: one GPU round trip per draw, and Rosetta's cost of re-protecting watched memory #24728
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 Jazeupoi on 2026-11-21T00:23:52Z.
Title and scene
PPSA69421 (SuperTuxKart 00.001.000), single race on Subsea (default kart, 1920x1080), seconds 40 to 60 after launch, accelerating from the start line.
What is slow or what changed
On macOS the race runs at about 10 FPS: frame p50 100 to 106 ms with the GPU busy about 20 ms per present. Measured on
main0a025bd3c6with #17425 and #11049 merged (needed for the macOS build, local merge367abdb9aee2). MacBook Air M4, macOS 27.0.1, MoltenVK 1.4.2, x86-64 Release under Rosetta 2.The frame is two costs in series on the title's one render thread. The title's own logic is about 2 % of its samples.
1. One GPU round trip per draw, about 55 per frame (about 50 ms). Queue 0x0 takes about 55 submissions per frame, and the title polls a label until each one completes before it builds the next (
sceKernelUsleep(1000)in a loop; it is asleep 54 % of the time). Of about 5,400 GPU batches in 20 s, 3,004 hold a single draw (GPU p50 0.19 ms). Every draw is full-scissor, so each batch is its own 1920x1080 render pass. One round trip takes about 1 ms: submit to GPU start p50 0.19 ms, GPU 0.25 ms, GPU end to the title's next packet 0.33 ms. Queue worker 0x0 waits 18.4 s of 20 s.The labels are not the issue. With the recorder idle,
WriteLabelOnGpualready writes them on the CPU (VulkanDevice.cpp:3149). Here a batch is always in flight. None of these changed the frame time (alternated runs, within the ±10 ms noise of this race):APS5_NO_LABEL_BATCHING,APS5_LABEL_TRY_EACH_PACKET,APS5_LABEL_FLUSH_US=0;QueueWorker.cpp:219);sceKernelUsleepcapped at 200 us;MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS=0(slower) andMVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE=2(slower) or3;MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS=1(black window).2. Writing watched memory is slow under Rosetta (about 21 ms per frame). The title fills about 43 MiB of write-watched memory per frame (a
vmovntdqloop atstk+0x52210and arep stoslatstk+0x31fe4), which took 7,151 write-watch faults per second. A standalone x86-64 test shows that most of the cost is Rosetta's, not the faults':So under Rosetta each protect and unprotect cycle costs about 0.2 ms for every MiB written afterwards (five times native), and each fault about 18 us more.
What helped (local builds, alternated with the unchanged build in one series):
FaultAheadBlock64 KiB → 1 MiB,APS5_WRITE_WATCH_FAULT_AHEAD=256The larger block cut the faults from 7,151 to 1,785 per second. I did not open a pull request for it because it touches the same fault-ahead as #20126. The polling watcher replaces
vkWaitSemaphoresKHRinRecorder::ProgressWatcherwithvkGetSemaphoreCounterValueKHRand a 20 us sleep. MoltenVK's host wait goes through anMTLSharedEventListenercallback and then a condition variable. On its own the change gave 103.3 against 106.6 ms over 9 alternated pairs, which is within the noise. Merging adjacent pages inWatch::untrap(onemprotectper page now) cutmprotectcalls by 69 % but did not change the frame time.What remains looks like a design question, not a setting. The cost left in part 2 comes from re-protecting buffers that the title rewrites in full every frame. Buffers like these could be left unwatched and uploaded each time, but I have not tried that.
Summary lines
6 lines: none, 1 MiB block, 1 MiB block + polling watcher, alternated
dirtyis true because those builds carry the local changes above.Traces
aps5-trace-367abdb9aee2-85838.json.gz,aps5-trace-367abdb9aee2-87537.json.gzaps5-trace-367abdb9aee2-86248.json.gz,aps5-trace-367abdb9aee2-87046.json.gzaps5-trace-367abdb9aee2-85355.json.gz,aps5-trace-367abdb9aee2-86649.json.gzCapture
Input came from
APS5_PAD_INPUT_FILE. The fault,mprotectand sleep counts come from separate runs of the same scene with a smallDYLD_INSERT_LIBRARIESlibrary.AI-assisted: yes (Claude Code)