Performance recipe: per-frame CPU copies and Wine backing on low-memory Macs #16

Open
opened 2026-11-27 14:01:21 +00:00 by github-bot · 4 comments
Owner

@⁠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.sh settings. 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

  • The process needs more memory than the Mac has. footprint at 150 s into a run puts it at 14 to 17 GB:
    • GPU driver memory (IOAccelerator): 6.1 to 6.9 GB;
    • unmapped graphics memory: 2.9 to 3.8 GB;
    • Wine's reserved range: 3.7 to 4.4 GB;
    • malloc: about 1.3 GB.
  • macOS pages the game's memory out to disk. Wine keeps anonymous sections (which back the title's physical memory) in temporary files (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.
  • That paging is what makes DirectStorage slow, not decompression. DirectStorage writes into title memory ran at only 0.01 to 0.2 GB/s, about 90 ms per frame per thread, while decompression took about 4 ms per frame.
  • The per-frame copies from title memory slow down when paging rises. VIctory copies about 170 to 217 MB of title memory into its host copies every frame: 167 ms of thread time at the median and 405 ms in the slowest 5% of frames. In the quarter of frames with the most page-outs, the copy rate drops from 1.88 to 0.84 GB/s. Copy speed and page-ins move together almost exactly (correlation −0.85).
  • Where VIctory holds memory (diagnostics build accounting):
    • title buffers: about 0.9 GB;
    • "loose windows", 256 KiB copies of title memory outside buffers: 3.3 to 3.9 GB in about 8,000 windows;
    • GPU-written textures: about 1.7 GB.
  • Where CPU samples land (one profile): 62% are outside every PE image, i.e. Wine's Unix side and page faults; 17% in victory.exe; 10% in mmdevapi (audio); under 1% in the title's own code.

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.

Idea Result Why
Back Wine's anonymous sections with shm_open instead of temp files (wineserver patch) 450 File page-outs fell from 7.7 GB to 12 MB, but swap-outs rose from 1.1 to 10.6 GB. The pressure only moved to swap.
VirtualLock every committed section (Wine maps it to mlock) 379 Locked pages force everything else out.
Drop loose windows unused for N frames (VICTORY_TRIM_HOST and gentler variants) 318 to 489 Next frame copies them back: copies rise from 170 to 250 MB per frame.
VICTORY_TEXTURE_DROP_MIPS=2 491 No gain beyond =1.
zlib-rs instead of the current inflate no change Decompression was never the limit.
VICTORY_ALIAS_BUFFERS=1 (zero-copy title buffers) no change Only 1 to 8 aliases are made in a run; see below.

The one thing that helped: a cheaper hash for victory-gpu's address maps, +3%. That is in #15.

Ideas still open

  1. Zero-copy for most title memory. Today an alias is made only when an XMemVirtualAlloc commit 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.
  2. Copy only what changed in loose windows. Fault tracking already marks written pages; the question is how much of the 170+ MB per frame is pages the title never touched.
  3. Run the prewarm copies during the GPU wait. The prewarm is meant to do copies ahead of time. It currently does 0 ms of work per frame, because one rule (host/unwaited.rs, about line 879) refuses every copy when any running list uses title memory. The other rules work per copy.
  4. A copy budget under memory pressure. The RAM-low gauge exists (resource.rs), but the copy path ignores it.
  5. Audio. 10% of CPU samples are in mmdevapi. Nobody has looked at why.
  6. Anything that lowers the working set below RAM. On a 24 GB Mac every GB freed is worth more than any per-frame CPU saving. More RAM probably helps a lot; numbers from a 32 GB or larger Mac running the same recipe would be useful.
**@⁠jgrizon** on GitHub · 2026-11-27 14:01 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/16) 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.sh` settings. 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 - **The process needs more memory than the Mac has.** `footprint` at 150 s into a run puts it at 14 to 17 GB: - GPU driver memory (IOAccelerator): 6.1 to 6.9 GB; - unmapped graphics memory: 2.9 to 3.8 GB; - Wine's reserved range: 3.7 to 4.4 GB; - malloc: about 1.3 GB. - **macOS pages the game's memory out to disk.** Wine keeps anonymous sections (which back the title's physical memory) in temporary files (`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. - **That paging is what makes DirectStorage slow, not decompression.** DirectStorage writes into title memory ran at only 0.01 to 0.2 GB/s, about 90 ms per frame per thread, while decompression took about 4 ms per frame. - **The per-frame copies from title memory slow down when paging rises.** VIctory copies about 170 to 217 MB of title memory into its host copies every frame: 167 ms of thread time at the median and 405 ms in the slowest 5% of frames. In the quarter of frames with the most page-outs, the copy rate drops from 1.88 to 0.84 GB/s. Copy speed and page-ins move together almost exactly (correlation −0.85). - **Where VIctory holds memory** (diagnostics build accounting): - title buffers: about 0.9 GB; - "loose windows", 256 KiB copies of title memory outside buffers: 3.3 to 3.9 GB in about 8,000 windows; - GPU-written textures: about 1.7 GB. - **Where CPU samples land** (one profile): 62% are outside every PE image, i.e. Wine's Unix side and page faults; 17% in victory.exe; **10% in mmdevapi (audio)**; under 1% in the title's own code. ## 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. | Idea | Result | Why | | --- | --- | --- | | Back Wine's anonymous sections with `shm_open` instead of temp files (wineserver patch) | 450 | File page-outs fell from 7.7 GB to 12 MB, but swap-outs rose from 1.1 to 10.6 GB. The pressure only moved to swap. | | `VirtualLock` every committed section (Wine maps it to `mlock`) | 379 | Locked pages force everything else out. | | Drop loose windows unused for N frames (`VICTORY_TRIM_HOST` and gentler variants) | 318 to 489 | Next frame copies them back: copies rise from 170 to 250 MB per frame. | | `VICTORY_TEXTURE_DROP_MIPS=2` | 491 | No gain beyond `=1`. | | zlib-rs instead of the current inflate | no change | Decompression was never the limit. | | `VICTORY_ALIAS_BUFFERS=1` (zero-copy title buffers) | no change | Only 1 to 8 aliases are made in a run; see below. | The one thing that helped: a cheaper hash for victory-gpu's address maps, +3%. That is in #15. ## Ideas still open 1. **Zero-copy for most title memory.** Today an alias is made only when an `XMemVirtualAlloc` commit 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. 2. **Copy only what changed in loose windows.** Fault tracking already marks written pages; the question is how much of the 170+ MB per frame is pages the title never touched. 3. **Run the prewarm copies during the GPU wait.** The prewarm is meant to do copies ahead of time. It currently does 0 ms of work per frame, because one rule (`host/unwaited.rs`, about line 879) refuses every copy when any running list uses title memory. The other rules work per copy. 4. **A copy budget under memory pressure.** The RAM-low gauge exists (`resource.rs`), but the copy path ignores it. 5. **Audio.** 10% of CPU samples are in mmdevapi. Nobody has looked at why. 6. **Anything that lowers the working set below RAM.** On a 24 GB Mac every GB freed is worth more than any per-frame CPU saving. More RAM probably helps a lot; numbers from a 32 GB or larger Mac running the same recipe would be useful.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:01:21 +00:00
Author
Owner

@⁠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:

  • buffer copies: 552 to 946 MB, then flat
  • host textures: 2.1 to 2.6 GB
  • placement heaps: 11 × 64 MiB
  • pipelines still being made: 1,416, falling to 0

The Rust heap grows too, from 964 MB to 2,746 MB; 544 MB of that is the VIEWS map in descriptor.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_HOST ages 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.

**@⁠jgrizon** on GitHub · 2026-11-27 18:58 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/16#issuecomment-7226057079) 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: - buffer copies: 552 to 946 MB, then flat - host textures: 2.1 to 2.6 GB - placement heaps: 11 × 64 MiB - pipelines still being made: 1,416, falling to 0 The Rust heap grows too, from 964 MB to 2,746 MB; 544 MB of that is the `VIEWS` map in `descriptor.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_HOST` ages 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.
Author
Owner

@⁠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

  • MacBook Pro, Apple M5 Max, 128 GB, macOS 27.2.1 (26B131).
  • halfwave50/VIctory-macOS-halfwave branch main-mac at 834f816, release profile, built with llvm-mingw 20261117 instead of Homebrew clang and lld.
  • Stock CrossOver 26.3 Wine with the bundled D3DMetal 3.0, not the recipe's patched Wine and not 4.0 beta 3. Our own patched build hangs during the title's 2 GB storage reservation, so absolute frame rates here are not comparable with PR #14's 3.9 fps.
  • Launched through runtime-preview/run.sh against a CrossOver bottle, with the launcher defaults of main-mac's play-main-mac.sh plus VICTORY_AMBIENT=1.0, VICTORY_HALVES_SHARED_LDS=0, VICTORY_OUTPUT=1280x720, VICTORY_PRESENT_PLANE=0, VICTORY_PRESENT_COMPOSITE=1.
  • Series S profile, render 853x480, output 1280x720. The precompiled 64-thread argument clamp is active.

Memory behaviour

Across every run in the world:

  • Swap used stayed at 0.25 MB of a 1 GB total and never grew. sysctl vm.swapusage was sampled repeatedly over runs of 6 to 15 minutes.
  • Resident memory peaked around 22 GB, against 128 GB installed.
  • VICTORY_TEXTURE_DROP_MIPS was 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:

Configuration World reports Median Median frame Max Median dropped draws
main-mac launcher defaults 22 1.3 fps 774 ms 3.4 352
+ VICTORY_BVH_BUILDER=1 91 3.4 fps 298 ms 11.5 13
+ desktop FidelityFX 2.3.0 via VICTORY_FIDELITYFX_DIR 55 2.8 fps 358 ms 4.6 13

Draws 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=1 was 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.

**@⁠xarvel-temp** on GitHub · 2026-11-27 19:57 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/16#issuecomment-7227041812) 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 - MacBook Pro, Apple M5 Max, 128 GB, macOS 27.2.1 (26B131). - `halfwave50/VIctory-macOS-halfwave` branch `main-mac` at `834f816`, release profile, built with llvm-mingw 20261117 instead of Homebrew clang and lld. - **Stock CrossOver 26.3 Wine with the bundled D3DMetal 3.0**, not the recipe's patched Wine and not 4.0 beta 3. Our own patched build hangs during the title's 2 GB storage reservation, so absolute frame rates here are not comparable with PR #14's 3.9 fps. - Launched through `runtime-preview/run.sh` against a CrossOver bottle, with the launcher defaults of `main-mac`'s `play-main-mac.sh` plus `VICTORY_AMBIENT=1.0`, `VICTORY_HALVES_SHARED_LDS=0`, `VICTORY_OUTPUT=1280x720`, `VICTORY_PRESENT_PLANE=0`, `VICTORY_PRESENT_COMPOSITE=1`. - Series S profile, render 853x480, output 1280x720. The precompiled 64-thread argument clamp is active. ### Memory behaviour Across every run in the world: - **Swap used stayed at 0.25 MB of a 1 GB total and never grew.** `sysctl vm.swapusage` was sampled repeatedly over runs of 6 to 15 minutes. - Resident memory peaked around **22 GB**, against 128 GB installed. - `VICTORY_TEXTURE_DROP_MIPS` was 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: | Configuration | World reports | Median | Median frame | Max | Median dropped draws | | --- | ---: | ---: | ---: | ---: | ---: | | `main-mac` launcher defaults | 22 | 1.3 fps | 774 ms | 3.4 | 352 | | + `VICTORY_BVH_BUILDER=1` | 91 | **3.4 fps** | 298 ms | 11.5 | **13** | | + desktop FidelityFX 2.3.0 via `VICTORY_FIDELITYFX_DIR` | 55 | 2.8 fps | 358 ms | 4.6 | 13 | Draws 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=1` was 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.
Author
Owner

@⁠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.

**@⁠paveledits** on GitHub · 2026-11-28 00:48 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/16#issuecomment-7231207697) 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.
Author
Owner

@⁠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:

  1. One release run, Series S, prison room or later, standing still. Paste three victory_gpu::host frame lines from minute 3, the ones that start N 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.
  2. The same run with VICTORY_FRAME_WAITS=1, if your build has it. That splits the GPU time into queue waits, fence waits and presentation.
  3. If you have time, the same run with D3DMetal 4.0 beta 3 in place of 3.0. Here it saved about 7 ms of GPU time once its pipeline cache was warm.

Please note the commit and the switches you set, and strip usernames and paths from the lines.

**@⁠jgrizon** on GitHub · 2026-11-28 06:36 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/16#issuecomment-7235407725) @⁠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: 1. One release run, Series S, prison room or later, standing still. Paste three `victory_gpu::host` frame lines from minute 3, the ones that start `N 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. 2. The same run with `VICTORY_FRAME_WAITS=1`, if your build has it. That splits the GPU time into queue waits, fence waits and presentation. 3. If you have time, the same run with D3DMetal 4.0 beta 3 in place of 3.0. Here it saved about 7 ms of GPU time once its pipeline cache was warm. Please note the commit and the switches you set, and strip usernames and paths from the lines.
github-bot changed title from 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 2026-11-28 18:02:56 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.