Performance recipe: where frame time and stutters go (copies, census lock, GPU) #18

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

Measurements from the performance recipe (runtime-preview/build.sh --perf), release builds, Series S intro, on an Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832 and D3DMetal 3.0. The numbers come from the 5-second frame lines across about 10 runs. Posting so others can check them or take one up.

Where a ~235 ms frame goes

Part Median Slowest 5% Note
Copies out of title memory 167 ms 405 ms Thread time on the 6-thread texture pool, about 217 MB per frame. Throttled by paging; see #16.
Texture uploads, same pool 33 ms 143 ms About 9 MB per frame.
Descriptor census lock, blocked 138 ms 194 ms Summed over threads, so it may overlap other work. VICTORY_SHARD_CENSUS exists but has only been tried bundled with other switches, in diagnostics builds. Upstream's VICTORY_SPANS_QUICK touches the same lock.
"On the GPU" 58 ms — A wait, so it also includes D3DMetal's translation and the fence signal back through Wine.
Pipeline compiles in steady play 0 0 About 2,700 pipelines are loaded or made by +40 s.

The slowest frames reached 577 ms at the 99th percentile and 2.1 to 4.7 s at worst. Half the frames wait only about 46 ms inside the runtime while taking 180 to 230 ms in total, so the time goes to the copy and upload phase.

GPU time

  • It barely depends on draw count:
    • 47.7 ms at 200 to 1,000 draws;
    • 57.4 ms at 2,000 to 3,000 draws;
    • 66.5 ms at 3,000 to 5,000 draws;
    • about 4.5 µs per extra draw.
      So the cost is pixel fill and memory traffic, not per-draw overhead.
  • VIctory adds an estimated 8 to 21 ms of it. These are cost estimates applied to measured counters:
    • 145 to 175 draw-count clamp dispatches per frame, which split the title's command lists 254 times;
    • 510 global UAV barriers out of about 3,200 barriers;
    • 15 to 27 texture copy-backs;
    • 3 to 6 depth-twin copies;
    • the present composite.
  • D3D12 timestamps can't be used: D3DMetal answers zero. Per-list wall time with VICTORY_GPU_TIMING=1 on a diagnostics build, and victory replay --timing on a recorded capture, have never been tried.
  • Even with all of VIctory's extra GPU work removed, the GPU alone would cap the game at about 20 to 27 fps.

Ideas, with estimated effect:

  • render internally at about 0.7× and upscale (20 to 28 ms, if the title's render size can be reached);
  • host copies in video memory in release (3 to 10 ms);
  • UAV barriers scoped to one resource (3 to 8 ms);
  • one clamp pass per execute instead of 145 (3 to 7 ms).

Upstream's new perf switches, first runs

World frames in the first 120 s, same day, our tree plus perf patches 0003 to 0011:

Run Frames
Control (without 0003 to 0011) 516
With VICTORY_SPANS_QUICK=1 VICTORY_DETILE_ROWS=1 VICTORY_FRAME_WAITS=1 474
Plus VICTORY_SHADER_OPT=2, second run with a warm cache 474 (slowest 5%: 350 ms, against 377 ms for the control)

That is about 8% fewer frames, inside the 10% to 30% run-to-run spread, so it is not proven. More runs are queued, and we'll add the results here.

**@⁠jgrizon** on GitHub · 2026-11-27 14:01 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/18) Measurements from the performance recipe (`runtime-preview/build.sh --perf`), release builds, Series S intro, on an Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832 and D3DMetal 3.0. The numbers come from the 5-second frame lines across about 10 runs. Posting so others can check them or take one up. ## Where a ~235 ms frame goes | Part | Median | Slowest 5% | Note | | --- | --- | --- | --- | | Copies out of title memory | 167 ms | 405 ms | Thread time on the 6-thread texture pool, about 217 MB per frame. Throttled by paging; see https://git.gtahub.st/github/paveledits--ScarlettMac/issues/16. | | Texture uploads, same pool | 33 ms | 143 ms | About 9 MB per frame. | | Descriptor census lock, blocked | 138 ms | 194 ms | Summed over threads, so it may overlap other work. `VICTORY_SHARD_CENSUS` exists but has only been tried bundled with other switches, in diagnostics builds. Upstream's `VICTORY_SPANS_QUICK` touches the same lock. | | "On the GPU" | 58 ms | — | A wait, so it also includes D3DMetal's translation and the fence signal back through Wine. | | Pipeline compiles in steady play | 0 | 0 | About 2,700 pipelines are loaded or made by +40 s. | The slowest frames reached 577 ms at the 99th percentile and 2.1 to 4.7 s at worst. Half the frames wait only about 46 ms inside the runtime while taking 180 to 230 ms in total, so the time goes to the copy and upload phase. ## GPU time - **It barely depends on draw count:** - 47.7 ms at 200 to 1,000 draws; - 57.4 ms at 2,000 to 3,000 draws; - 66.5 ms at 3,000 to 5,000 draws; - about 4.5 µs per extra draw. So the cost is pixel fill and memory traffic, not per-draw overhead. - **VIctory adds an estimated 8 to 21 ms of it.** These are cost estimates applied to measured counters: - 145 to 175 draw-count clamp dispatches per frame, which split the title's command lists 254 times; - 510 global UAV barriers out of about 3,200 barriers; - 15 to 27 texture copy-backs; - 3 to 6 depth-twin copies; - the present composite. - **D3D12 timestamps can't be used:** D3DMetal answers zero. Per-list wall time with `VICTORY_GPU_TIMING=1` on a diagnostics build, and `victory replay --timing` on a recorded capture, have never been tried. - **Even with all of VIctory's extra GPU work removed,** the GPU alone would cap the game at about 20 to 27 fps. Ideas, with estimated effect: - render internally at about 0.7× and upscale (20 to 28 ms, if the title's render size can be reached); - host copies in video memory in release (3 to 10 ms); - UAV barriers scoped to one resource (3 to 8 ms); - one clamp pass per execute instead of 145 (3 to 7 ms). ## Upstream's new perf switches, first runs World frames in the first 120 s, same day, our tree plus perf patches 0003 to 0011: | Run | Frames | | --- | --- | | Control (without 0003 to 0011) | 516 | | With `VICTORY_SPANS_QUICK=1 VICTORY_DETILE_ROWS=1 VICTORY_FRAME_WAITS=1` | 474 | | Plus `VICTORY_SHADER_OPT=2`, second run with a warm cache | 474 (slowest 5%: 350 ms, against 377 ms for the control) | That is about 8% fewer frames, inside the 10% to 30% run-to-run spread, so it is not proven. More runs are queued, and we'll add the results here.
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 15:03 UTC · original

Correction to the "upstream's new perf switches" table above: the roughly 8% gap was noise, not the patches.

More runs of our tree plus patches 0003 to 0011 with no extra switches gave 487 and 603 world frames in the first 120 s. The 603 run had VICTORY_COPIES_IN_VIDEO_MEMORY=1 set, but that switch turned out to do nothing (see below), so it counts as a plain run. The control gave 516 and 559. On this 24 GB Mac a single run can swing from about 450 to 600 depending on how much swap the system already holds, so any comparison needs several interleaved runs.

Two more findings:

  • Lowering the render scale did not change GPU time. VICTORY_RES_SCALE=0.5 (the title's render scale and its ceiling, both patched to 0.5) applied, but "on the GPU" stayed at about 55 ms per frame. So the ~58 ms GPU wait is not pixel fill.
  • D3DMetal does not report GPU upload heaps. The D3D12_OPTIONS16 check fails, so host copies cannot be placed in video memory this way.
**@⁠jgrizon** on GitHub · 2026-11-27 15:03 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/18#issuecomment-7221576916) Correction to the "upstream's new perf switches" table above: the roughly 8% gap was noise, not the patches. More runs of our tree plus patches 0003 to 0011 with no extra switches gave 487 and 603 world frames in the first 120 s. The 603 run had `VICTORY_COPIES_IN_VIDEO_MEMORY=1` set, but that switch turned out to do nothing (see below), so it counts as a plain run. The control gave 516 and 559. On this 24 GB Mac a single run can swing from about 450 to 600 depending on how much swap the system already holds, so any comparison needs several interleaved runs. Two more findings: - **Lowering the render scale did not change GPU time.** `VICTORY_RES_SCALE=0.5` (the title's render scale and its ceiling, both patched to 0.5) applied, but "on the GPU" stayed at about 55 ms per frame. So the ~58 ms GPU wait is not pixel fill. - **D3DMetal does not report GPU upload heaps.** The `D3D12_OPTIONS16` check fails, so host copies cannot be placed in video memory this way.
Author
Owner

@⁠jgrizon on GitHub · 2026-11-27 18:58 UTC · original

Follow-up: where the per-frame buffer copies come from, and two switches that did not pay.

Copies: 64 KiB guard pages and repeated small writes. Buffer refreshes copy 206 to 278 MB a frame. None of it is an untracked whole-range copy (copied whole (not tracked) 0.0 MB), and guards are not missed. The title writes to 2,592 to 3,160 distinct 64 KiB pages a frame, which is 166 MB: the refresh volume is exactly those pages at 64 KiB each. The same pages are re-dirtied two or three times a frame, about 9,500 page takes in all. The 4 KiB comparison finds 445 to 690 MB of unchanged subpages a frame inside those pages. The title writes a little in each page, but we still read the whole page to find out: about 380 MB of reads a frame. The comparison saves the write, not the read.

Two smaller self-inflicted costs:

  • Copy-back through views marks the whole block it writes (43 MB).
  • Withheld pages are re-read from title memory although the title never wrote them.

The real cut is 4 KiB write tracking. Title memory is allocated MEM_WRITE_WATCH, but GetWriteWatch alone is not safe here. Our handler opens the whole 64 KiB block on the first fault, so later writes to that block never fault and Wine never reports them. Copying only the reported subpages would drop writes. The safe version opens only the faulting 4 KiB page. That means more faults, and each fault is expensive under Wine. A per-buffer census line (VICTORY_BUFFER_COPY_CENSUS=1) is in testing first, to measure the ratio of dirty pages to subpages actually copied.

Not worth it (release, world frames in the first 120 s):

  • VICTORY_BUILDER_EVERY=3 or 4 (builder every Nth frame): 537 and 422 at 3, 424 and 375 at 4, against 443 and 421 at every frame. That is noise.
  • VICTORY_FLIGHTS_RANGES=1: 401 and 371 with it, 443 and 421 without, with the same median fps. Its tests pass.

The GPU wait stays at 55 to 75 ms a frame, in about 30 round trips of about 1.9 ms each. It does not scale with pixels: RES_SCALE=0.5 left GPU time unchanged. D3DMetal 3.0 has no GPU upload heaps (D3D12_OPTIONS16), and its timestamps read 0, which matches synthetic Check #38.

**@⁠jgrizon** on GitHub · 2026-11-27 18:58 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/18#issuecomment-7226057373) Follow-up: where the per-frame buffer copies come from, and two switches that did not pay. **Copies: 64 KiB guard pages and repeated small writes.** Buffer refreshes copy 206 to 278 MB a frame. None of it is an untracked whole-range copy (`copied whole (not tracked) 0.0 MB`), and guards are not missed. The title writes to 2,592 to 3,160 distinct 64 KiB pages a frame, which is 166 MB: the refresh volume is exactly those pages at 64 KiB each. The same pages are re-dirtied two or three times a frame, about 9,500 page takes in all. The 4 KiB comparison finds 445 to 690 MB of unchanged subpages a frame inside those pages. The title writes a little in each page, but we still read the whole page to find out: about 380 MB of reads a frame. The comparison saves the write, not the read. Two smaller self-inflicted costs: - Copy-back through views marks the whole block it writes (43 MB). - Withheld pages are re-read from title memory although the title never wrote them. The real cut is 4 KiB write tracking. Title memory is allocated `MEM_WRITE_WATCH`, but `GetWriteWatch` alone is not safe here. Our handler opens the whole 64 KiB block on the first fault, so later writes to that block never fault and Wine never reports them. Copying only the reported subpages would drop writes. The safe version opens only the faulting 4 KiB page. That means more faults, and each fault is expensive under Wine. A per-buffer census line (`VICTORY_BUFFER_COPY_CENSUS=1`) is in testing first, to measure the ratio of dirty pages to subpages actually copied. **Not worth it (release, world frames in the first 120 s):** - `VICTORY_BUILDER_EVERY=3` or `4` (builder every Nth frame): 537 and 422 at 3, 424 and 375 at 4, against 443 and 421 at every frame. That is noise. - `VICTORY_FLIGHTS_RANGES=1`: 401 and 371 with it, 443 and 421 without, with the same median fps. Its tests pass. **The GPU wait** stays at 55 to 75 ms a frame, in about 30 round trips of about 1.9 ms each. It does not scale with pixels: `RES_SCALE=0.5` left GPU time unchanged. D3DMetal 3.0 has no GPU upload heaps (`D3D12_OPTIONS16`), and its timestamps read 0, which matches synthetic Check #38.
Author
Owner

@⁠paveledits on GitHub · 2026-11-28 00:48 UTC · original

I ran a paired Series S test on a 48 GB M3 Max with the same executable and toggled ordered descriptor key reuse. Stationary scans went from 11.67 million to 3.57 million visits per frame while both arms emitted roughly 58,000 ranges per frame. The estimated summed lock hold went from 54.36 to 19.17 thread-ms per stationary frame. Walking median improved from 411.6 to 385.6 ms per frame with similar draw counts.

The later hold ended at a different camera angle and had 13% more draws with the cache enabled. It ran slower, so a repeat with the same final view is needed. A separate 7.29-second Metal trace measured 33.4% game engine occupancy. The runtime’s GPU/wait bucket also includes submission and fence waits. Copy attribution and a repeat remain open.

**@⁠paveledits** on GitHub · 2026-11-28 00:48 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/18#issuecomment-7231208145) I ran a paired Series S test on a 48 GB M3 Max with the same executable and toggled ordered descriptor key reuse. Stationary scans went from 11.67 million to 3.57 million visits per frame while both arms emitted roughly 58,000 ranges per frame. The estimated summed lock hold went from 54.36 to 19.17 thread-ms per stationary frame. Walking median improved from 411.6 to 385.6 ms per frame with similar draw counts. The later hold ended at a different camera angle and had 13% more draws with the cache enabled. It ran slower, so a repeat with the same final view is needed. A separate 7.29-second Metal trace measured 33.4% game engine occupancy. The runtime’s GPU/wait bucket also includes submission and fence waits. Copy attribution and a repeat remain open.
Author
Owner

@⁠jgrizon on GitHub · 2026-11-28 06:36 UTC · original

Thanks for the paired test. Ordered key reuse cut census visits by about 70% (11.67 million to 3.57 million), which is worth porting.

Where does the code live: which repo, branch or commit? I'd like to add it to the performance recipe and A/B it on the 24 GB M5 Pro.

On the repeat you mention: we now start every run from a pinned save and compare world minutes 2 to 6, so each run starts in the same place with the same view. Identical runs land within about 3% of each other.

**@⁠jgrizon** on GitHub · 2026-11-28 06:36 UTC · [original](https://github.com/paveledits/ScarlettMac/issues/18#issuecomment-7235408012) Thanks for the paired test. Ordered key reuse cut census visits by about 70% (11.67 million to 3.57 million), which is worth porting. Where does the code live: which repo, branch or commit? I'd like to add it to the performance recipe and A/B it on the 24 GB M5 Pro. On the repeat you mention: we now start every run from a pinned save and compare world minutes 2 to 6, so each run starts in the same place with the same view. Identical runs land within about 3% of each other.
This discussion has been locked. Commenting is limited to contributors.
No description provided.