Performance recipe: where frame time and stutters go (copies, census lock, GPU) #18
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#18
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
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
VICTORY_SHARD_CENSUSexists but has only been tried bundled with other switches, in diagnostics builds. Upstream'sVICTORY_SPANS_QUICKtouches the same lock.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
So the cost is pixel fill and memory traffic, not per-draw overhead.
VICTORY_GPU_TIMING=1on a diagnostics build, andvictory replay --timingon a recorded capture, have never been tried.Ideas, with estimated effect:
Upstream's new perf switches, first runs
World frames in the first 120 s, same day, our tree plus perf patches 0003 to 0011:
VICTORY_SPANS_QUICK=1 VICTORY_DETILE_ROWS=1 VICTORY_FRAME_WAITS=1VICTORY_SHADER_OPT=2, second run with a warm cacheThat 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 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=1set, 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:
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.D3D12_OPTIONS16check fails, so host copies cannot be placed in video memory this way.@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:
The real cut is 4 KiB write tracking. Title memory is allocated
MEM_WRITE_WATCH, butGetWriteWatchalone 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=3or4(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.5left GPU time unchanged. D3DMetal 3.0 has no GPU upload heaps (D3D12_OPTIONS16), and its timestamps read 0, which matches synthetic Check #38.@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.
@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.