Performance recipe: per-frame CPU copies and Wine backing on low-memory Macs #16
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/paveledits--ScarlettMac#16
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?
@jgrizon on GitHub · 2026-11-27 14:01 UTC · original
These are measurements from the performance recipe (
runtime-preview/build.sh --perf). Short version: the game world is limited by memory, not by the GPU or shader compiles. Below is what we measured, what we tried that did not help, and ideas still open. Anyone who wants to pick one up is welcome.Setup: Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832, D3DMetal 3.0, patched CrossOver Wine, Series S intro, release build,
play-main-mac.shsettings. Typical result: about 520 world frames in the first 120 s (about 4.3 fps, a median frame of about 235 ms).What we measured
footprintat 150 s into a run puts it at 14 to 17 GB:server/mapping.c,create_temp_file). Per 4-minute run, macOS writes 7 to 10 GB of those pages to disk and reads back about 20 to 34 GB.What we tried that did not help
The numbers are world frames in the first 120 s. The same-day baseline was 488 to 532.
shm_openinstead of temp files (wineserver patch)VirtualLockevery committed section (Wine maps it tomlock)VICTORY_TRIM_HOSTand gentler variants)VICTORY_TEXTURE_DROP_MIPS=2=1.VICTORY_ALIAS_BUFFERS=1(zero-copy title buffers)The one thing that helped: a cheaper hash for victory-gpu's address maps, +3%. That is in #15.
Ideas still open
XMemVirtualAlloccommit is plain read-write, not a placeholder and whole 64 KiB pages. Only the 8 big pools (about 3 GB) pass. The per-frame copy path never asks for an alias. We are testing a switch that aliases buffer and loose-window title memory in place. The catch: an earlier run measured aliased (host-memory) reads at about +20 ms of GPU time per frame.host/unwaited.rs, about line 879) refuses every copy when any running list uses title memory. The other rules work per copy.resource.rs), but the copy path ignores it.@jgrizon on GitHub · 2026-11-27 18:58 UTC · original
Follow-up on long sessions: what grows, and why the existing caps miss it.
What grows. It is VIctory's copies of title memory outside buffers (the loose windows). In three different builds they grow steadily, with no limit, at about 15 MB/s: 57 MB at the first report, 4,466 MB after 227 s. Everything else levels off:
The Rust heap grows too, from 964 MB to 2,746 MB; 544 MB of that is the
VIEWSmap indescriptor.rs. In a 600 s release run, swap is flat for four minutes, then grows by 4.7 GB. Peak resident memory is 10.4 GB, and free RAM falls to 4%.Why the caps miss. Each cap is keyed to the card's memory budget or to the clock. The texture trim is on and gives up 14 to 267 MB per report. Even so, host textures stay at 2.1 to 2.6 GB, because only the part it is allowed to evict can go.
VICTORY_TRIM_HOSTages windows by frames. At 0.7 to 2 fps, 60 frames is 30 to 85 s, so it holds loose windows to about 1.6 GB but costs 490 ms of copying a frame instead of 215 ms. Nothing caps the Rust heap.Being tested.
VICTORY_LOOSE_CAP_MB=<n>caps loose windows by size, not age. Windows are freed least recently used first, and never one used in the last 10 frames. A diagnostics line counts how many freed windows are made again soon after, which measures churn. 10-minute runs at 1 GB, 2 GB and no cap are under way, and I will post the numbers.Physical page sharing: parked. Sharing physical pages between title memory and host copies set off a lookup storm: about 170,000 ranges served and 89,000 copied anyway each frame. It added 35 to 50 ms of GPU time. It also needs
VICTORY_FLIGHTS=0, which costs about 30 ms of GPU time on its own. Not worth pursuing in this form.@xarvel-temp on GitHub · 2026-11-27 19:57 UTC · original
Numbers from a 128 GB Mac, since the issue asks for 32 GB or larger. The short version: with memory pressure entirely absent, the world is still about 3 fps, so on this machine paging is not what limits it.
Setup, and how it differs from yours
halfwave50/VIctory-macOS-halfwavebranchmain-macat834f816, release profile, built with llvm-mingw 20261117 instead of Homebrew clang and lld.runtime-preview/run.shagainst a CrossOver bottle, with the launcher defaults ofmain-mac'splay-main-mac.shplusVICTORY_AMBIENT=1.0,VICTORY_HALVES_SHARED_LDS=0,VICTORY_OUTPUT=1280x720,VICTORY_PRESENT_PLANE=0,VICTORY_PRESENT_COMPOSITE=1.Memory behaviour
Across every run in the world:
sysctl vm.swapusagewas sampled repeatedly over runs of 6 to 15 minutes.VICTORY_TEXTURE_DROP_MIPSwas reporting 3,270 textures with fewer mips and 2.1 GB saved at its peak. Turning it off (=0) produced no frame-rate change we could measure and no swap growth, which matches your point from the other direction: on a Mac with ample RAM the memory switches buy nothing, and their detail cost is pure loss.So every mechanism this issue describes — section files paged out, the working set exceeding RAM, every GB freed being worth more than a CPU saving — is simply inactive here.
Frame rate in the world
Medians over world frames only (frame reports with more than 500 draws, to exclude loading screens), one run per row:
main-maclauncher defaultsVICTORY_BVH_BUILDER=1VICTORY_FIDELITYFX_DIRDraws per frame were 1,292 (defaults) and about 3,150 to 3,229 in the other two, so the last two rows are a fair comparison with each other.
Caveats, in the spirit of your own variance guidance: these are single runs, and you report 10 to 30 % swing between runs with a 3 % significance bar. The 1.3 to 3.4 step and the 352 to 13 step are far outside that; the 3.4 versus 2.8 difference is not, although the draw counts match closely.
What this suggests
VICTORY_BVH_BUILDER=1was the single largest change we made, and it is not a memory change: it took dropped draws from 352 to 13 per frame and roughly tripled the median. With the builder held back by the halves interlock, 100 % of our steady-state drops were the BVH builder, matching #17.Given that a machine with no paging at all lands in the same 3 to 4 fps range as the 24 GB measurements, the remaining limit here looks like per-frame CPU work rather than the working set — which is what #18 measures. We have not instrumented the frame breakdown on this machine, so that is an inference, not a measurement: release builds on this branch print no per-reason drop report.
Happy to run specific experiments on this hardware if that would help, including a frame breakdown with a diagnostics build, or a sweep of any switch you want numbers for at 128 GB.
@paveledits on GitHub · 2026-11-28 00:48 UTC · original
I checked the 48 GB M3 Max with Series S output. With stock Wine section backing, startup free space fell by 806 MiB before the disk guard stopped the run at 50.7 seconds. With the section files on the external volume, 4.12 GiB was allocated there and the run reached the prison room. Both runs sampled zero macOS swap.
Two later room runs stayed at memory pressure level 1 with zero sampled swap and walked at 2.43 and 2.59 FPS. The placement change helped startup disk capacity on this setup. File-level paging and its contribution to frame time on the 24 GB machine remain open.
@jgrizon on GitHub · 2026-11-28 06:36 UTC · original
@xarvel-temp Thanks. Your numbers and the 48 GB M3 Max runs above both show zero swap at about 3 fps, so this issue's title is wrong: paging is not what limits the world. The limit is per-frame CPU work.
I'd like to take you up on your offer. Three small runs, most useful first:
victory_gpu::hostframe lines from minute 3, the ones that startN fps, N ms/frame (N preparing: copies N ms N MB, .... On our 24 GB M5 Pro a steady frame takes about 284 ms: 196 ms preparing, of which copies take 135 ms for 240 MB, plus 70 ms on the GPU. If your copies take the same time for the same MB, the cost is CPU work (write faults under Rosetta and the 64 KiB page compare), not memory.VICTORY_FRAME_WAITS=1, if your build has it. That splits the GPU time into queue waits, fence waits and presentation.Please note the commit and the switches you set, and strip usernames and paths from the lines.
Performance recipe: the world is memory-bound (macOS pages title memory out of Wine's section files)to Performance recipe: per-frame CPU copies and Wine backing on low-memory Macs