Memory churn and waits on the frame path: window reuse, buffer pools, FSR and audio off the title's threads #104

Closed
github-bot wants to merge 0 commits from github-bot/gh-104 into main AGit
Owner

@⁠rcioletti on GitHub · 2026-12-01 13:19 UTC · original
rcioletti:pr/memory-and-waits → main · +33 −1 · 2 files · 29 commits · closed without merging

Seven commits (the buffer pool and the send spares are one), found by profiling one PC (logs, the release profiler, a WPR CPU trace with context switches). Every code change has a switch to turn it back.

What's in it

Commit Change Switch
Windows reuse their cell's window A sized ask that finds no window of its own takes its 4 MiB cell's window when one exists, instead of making a 512 KiB duplicate. VICTORY_WINDOW_SHARE_CELL=0 turns it off
Window buffer pool Windows' shared buffers go back to a pool (exact size, zeroed on reuse, only when nothing else holds them) instead of being made and dropped about 65 times a second. VICTORY_WINDOW_POOL_MB (256; 0 off)
Launcher: send spares 512 MB of spare send buffers on PCs with 24 GB or more (was 128). launcher
Launcher: idle host lists 512 idle host lists on PCs with 24 GB or more (was 128; about 650 are in use in the city). launcher
Launcher: High on 16 GB cards Textures stop at 88% of VRAM and go from 84% (was 95/91). launcher
FSR recorded in order, not waited for ffxDispatch puts the upscale into the list's written-down stream; the list's translation thread records it there. Before, the title's render thread waited in external::record for everything the list had recorded to be translated. VICTORY_FFX_LATER=0
Opus decoding on its own thread XApuEnqueueCommand queues the command; a thread per connection decodes in order and XApuDequeueResult returns pending until it's done, as the console's audio hardware does. VICTORY_APU_ASYNC=0
Translation under elevated pressure 4 threads instead of 2 when free commit is under 3.5 GB (1 under 2.5 GB, unchanged). Logs how long translation waited for a turn. VICTORY_THIN_ELEVATED_THREADS

Why and what it did

Test PC: Intel Core i5-14600KF, RX 9060 XT 16 GB, 32 GB RAM, Windows 11. Series S, 1080p, High, FSR 4 Quality with FSR 4 frame generation.

Caveat: these are single sessions of ordinary play, not alternated A/B pairs, and areas differ between them. Frame times are compared at equal draw counts where it matters.

  • Window reuse. Windows held about 4 GB over 2.6 GB of title memory, much of it 512 KiB duplicates of 4 MiB cell windows. Next session: emergency GPU/commit reclaims 181 → 0, 14.3 → 17.1 fps, frames over 100 ms 15.6% → 9.3%, over 200 ms 144 → 43.
  • Buffer pool and send spares. The release profiler put 60% of hitch time in D3D buffer creation; VICTORY_SHARED_TALLY traced it to shadow::loose (65 buffers a second) and send.rs upload buffers. Per minute of play: window buffer creation 1645 → 563 MiB, send buffers 878 → 198 MiB, allocation stalls over 50 ms 4.3 → 1.6. That session ran 22.5 fps at a median of 6,526 draws (the one before: 19.1 fps at 5,908).
  • Texture headroom on 16 GB cards. VRAM was at its budget in 41% of samples; with 88/84 it was 6%, and textures looked the same.
  • FSR. A wait analysis of the trace (who readied whom) showed the title's five render threads blocked in thin::for_external for about 16 s of 30 s together, about 24 ms per frame on the title's frame path. In a 48-minute session afterwards: 24.3 → 25.1 fps, frames over 100 ms 2.2% → 1.3%, frames of 9,000+ draws 52.6 → 50.3 ms. Part of the wait moved to the submission, which waits for translation.
  • Audio. In the trace, the busiest title thread ran at 91% of a core and about 45% of that was our Opus decoding inside XApuEnqueueCommand. Moving it off didn't change the frame rate here (that thread wasn't the limit), but it frees most of a core, which may matter on slower CPUs. Sound was unchanged.
  • Translation throttle. In the traced session free commit was under 3.5 GB 91% of the time (median 2.6 GB), so recording_concurrency_cap held translation to 2 threads; on the critical path, translation threads woke each other some 35,000 times in 30 s at the top of their loop. The same PC with about 8 GB free ran far better. Not measured since; the new log line shows whether the cap acts.

Testing

  • cargo build --release --locked -p victory: no warnings.
  • Both CI clippy passes are clean for these changes. main itself fails three lints in files this PR doesn't touch (draw.rs same-type casts, rehydrate_prep.rs is_multiple_of, gameinput.rs assert_eq! with a bool); I ran clippy with only those three allowed.
  • cargo test --workspace --locked --exclude victory-gpu passes, except switches::documented_switches_are_read, which fails on main too (the README's placeholder VICTORY_NAME). One shader test, read_by_index, was skipped: it crashes the AMD driver on this PC.
  • victory-gpu, per CONTRIBUTING not the whole suite: the 56 tests for windows, list translation and external recording pass, one at a time.
  • New test: decodes_on_its_own_thread_in_the_order_of_the_commands (victory-hle).
  • Play: several sessions of 10 to 48 minutes with these changes, no crash, no FSR errors.
**@⁠rcioletti** on GitHub · 2026-12-01 13:19 UTC · [original](https://github.com/eikkapine/justanxboxemulator/pull/104) `rcioletti:pr/memory-and-waits` → `main` · +33 −1 · 2 files · 29 commits · closed without merging Seven commits (the buffer pool and the send spares are one), found by profiling one PC (logs, the release profiler, a WPR CPU trace with context switches). Every code change has a switch to turn it back. ## What's in it | Commit | Change | Switch | |---|---|---| | Windows reuse their cell's window | A sized ask that finds no window of its own takes its 4 MiB cell's window when one exists, instead of making a 512 KiB duplicate. | `VICTORY_WINDOW_SHARE_CELL=0` turns it off | | Window buffer pool | Windows' shared buffers go back to a pool (exact size, zeroed on reuse, only when nothing else holds them) instead of being made and dropped about 65 times a second. | `VICTORY_WINDOW_POOL_MB` (256; 0 off) | | Launcher: send spares | 512 MB of spare send buffers on PCs with 24 GB or more (was 128). | launcher | | Launcher: idle host lists | 512 idle host lists on PCs with 24 GB or more (was 128; about 650 are in use in the city). | launcher | | Launcher: High on 16 GB cards | Textures stop at 88% of VRAM and go from 84% (was 95/91). | launcher | | FSR recorded in order, not waited for | `ffxDispatch` puts the upscale into the list's written-down stream; the list's translation thread records it there. Before, the title's render thread waited in `external::record` for everything the list had recorded to be translated. | `VICTORY_FFX_LATER=0` | | Opus decoding on its own thread | `XApuEnqueueCommand` queues the command; a thread per connection decodes in order and `XApuDequeueResult` returns pending until it's done, as the console's audio hardware does. | `VICTORY_APU_ASYNC=0` | | Translation under elevated pressure | 4 threads instead of 2 when free commit is under 3.5 GB (1 under 2.5 GB, unchanged). Logs how long translation waited for a turn. | `VICTORY_THIN_ELEVATED_THREADS` | ## Why and what it did **Test PC:** Intel Core i5-14600KF, RX 9060 XT 16 GB, 32 GB RAM, Windows 11. Series S, 1080p, High, FSR 4 Quality with FSR 4 frame generation. **Caveat:** these are single sessions of ordinary play, not alternated A/B pairs, and areas differ between them. Frame times are compared at equal draw counts where it matters. - **Window reuse.** Windows held about 4 GB over 2.6 GB of title memory, much of it 512 KiB duplicates of 4 MiB cell windows. Next session: emergency GPU/commit reclaims 181 → 0, 14.3 → 17.1 fps, frames over 100 ms 15.6% → 9.3%, over 200 ms 144 → 43. - **Buffer pool and send spares.** The release profiler put 60% of hitch time in D3D buffer creation; `VICTORY_SHARED_TALLY` traced it to `shadow::loose` (65 buffers a second) and `send.rs` upload buffers. Per minute of play: window buffer creation 1645 → 563 MiB, send buffers 878 → 198 MiB, allocation stalls over 50 ms 4.3 → 1.6. That session ran 22.5 fps at a median of 6,526 draws (the one before: 19.1 fps at 5,908). - **Texture headroom on 16 GB cards.** VRAM was at its budget in 41% of samples; with 88/84 it was 6%, and textures looked the same. - **FSR.** A wait analysis of the trace (who readied whom) showed the title's five render threads blocked in `thin::for_external` for about 16 s of 30 s together, about 24 ms per frame on the title's frame path. In a 48-minute session afterwards: 24.3 → 25.1 fps, frames over 100 ms 2.2% → 1.3%, frames of 9,000+ draws 52.6 → 50.3 ms. Part of the wait moved to the submission, which waits for translation. - **Audio.** In the trace, the busiest title thread ran at 91% of a core and about 45% of that was our Opus decoding inside `XApuEnqueueCommand`. Moving it off didn't change the frame rate here (that thread wasn't the limit), but it frees most of a core, which may matter on slower CPUs. Sound was unchanged. - **Translation throttle.** In the traced session free commit was under 3.5 GB 91% of the time (median 2.6 GB), so `recording_concurrency_cap` held translation to 2 threads; on the critical path, translation threads woke each other some 35,000 times in 30 s at the top of their loop. The same PC with about 8 GB free ran far better. Not measured since; the new log line shows whether the cap acts. ## Testing - `cargo build --release --locked -p victory`: no warnings. - Both CI clippy passes are clean for these changes. `main` itself fails three lints in files this PR doesn't touch (`draw.rs` same-type casts, `rehydrate_prep.rs` `is_multiple_of`, `gameinput.rs` `assert_eq!` with a bool); I ran clippy with only those three allowed. - `cargo test --workspace --locked --exclude victory-gpu` passes, except `switches::documented_switches_are_read`, which fails on `main` too (the README's placeholder `VICTORY_NAME`). One shader test, `read_by_index`, was skipped: it crashes the AMD driver on this PC. - victory-gpu, per CONTRIBUTING not the whole suite: the 56 tests for windows, list translation and external recording pass, one at a time. - New test: `decodes_on_its_own_thread_in_the_order_of_the_commands` (victory-hle). - Play: several sessions of 10 to 48 minutes with these changes, no crash, no FSR errors.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
On the 512 KiB grid a root view made its 4 MiB cell's window and every ask
with a length in the same memory made a second window inside it: 4,052 MB
of windows over 2,609 MB of title memory (RX 9060 XT, 32 GB, RAM at 99%).
Such an ask now takes the cell's window when it is there and its own is not.
Its own window, when there, still comes first, and the cell's goes only
once nothing holds it, so slots keep finding the copy they took.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
At the base's 95/91 the card sat at its budget (lowered by Windows from
15.4 to 14.75 GB during play) 41% of the time, and each new buffer then
waited for the driver to evict: 60% of the slow frames' time was buffer
creation, up to 11 s at once (RX 9060 XT, 32 GB, VICTORY_PHASE2_PROFILE=1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows go after VICTORY_WINDOW_IDLE_MS and are made again when asked for;
each made its shared buffer anew: 65 a second, 4.7 GB a minute (the
city), and buffer creation was 28-63% of slow frames' time. A window's
shared buffer now goes to a pool by size when nothing else holds it, and
the next window of that size takes it, zeroed as a new one is.

The launcher kept 128 MB of send spares, so the big ones (64-128 MB) were
let go and made again, 2.5 GB a minute; 512 MB on 24 GB and more.

Measured with VICTORY_SHARED_TALLY=1 and VICTORY_PHASE2_PROFILE=1 on an
RX 9060 XT, 32 GB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console's decoder works beside the title; we decoded each command in
the title's XApuEnqueueCommand. A CPU profile (RX 9060 XT, i5-14600KF, the
city) showed the title's busiest thread at 91% of a core, 45% of it Opus
decoding in that call. Commands now go to a decoding thread per connection,
in order; a result's place is kept when the command is queued and filled
when it is decoded, and XApuDequeueResult answers PENDING_RESULTS until
the first is (the title polls for results already). Disconnect waits for
the thread. A test drives the threaded path; the in-call tests stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title's render thread waited in external::record for its list's whole
backlog to be translated: about 24 ms a frame in a CPU trace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:22:24 +00:00
github-bot closed this pull request 2026-12-01 19:52:13 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.