CPU profile: Opus decoding (XApu) runs on a game thread; another game thread spends ~26% yielding while no thread is maxed #137

Open
opened 2026-12-02 00:15:37 +00:00 by github-bot · 1 comment
Owner

@⁠weneedbucks on GitHub · 2026-12-02 00:13 UTC · original

System

  • Intel i7-10700K (all-core 5.0 GHz, AVX offset 0), RX 9060 XT 16 GB (RDNA 4), 32 GB RAM
  • CachyOS (kernel 7.3), system Wine 11.23, this repo's patched Mesa and vkd3d-proton from setup.sh
  • Series S profile, 1920x1080 output, uncapped, fullscreen, VICTORY_PAGES=0 unless stated

Note: this is an Intel CPU (no sse4a/clzero/mwaitx, which VIctory emulates). As far as I know, development has been on Ryzen, so timing may differ.

Title: CPU profile: Opus decoding (XApu) runs on a game thread; another game thread spends ~26% yielding while no thread is maxed

Build: profiled on 37bb30f (release, debug = "line-tables-only"). apu.rs is unchanged in f7f0360, so section 1 still applies.
Settings: VICTORY_UPSCALER=6 (the title's own upscaler) at the time.

Two flat perf profiles taken during city driving. Call-graph recording (-g) failed under Wine here, so these show where time goes, not who called what. xmem addresses were resolved against victory.pdb with llvm-symbolizer. Game addresses are offsets into the mapped game image.

1. Opus decoding runs synchronously on the calling game thread

Profile A: ray tracing on, busiest thread (~76% busy), 60 s, 42,929 samples.
Profile B: ray tracing off, all threads, 30 s, 310,516 samples. The same thread was again the busiest (70% busy).

Profile A Profile B
Game code 55.4% 59.2%
xmem (almost all opus_pure) 32.0% 29.1%
ucrtbase (memcpy loop + memset) 11.6% 11.3%

The top xmem functions in profile B are celt::mdct::MdctLookup::backward (4.6%), celt::bands::quant_partition (4.5%), CeltDecoder::decode_impl_from_rc (3.8%), silk_decode_frame (2.4%), and the SILK resamplers (iir_fir_block and up2_hq, 3.4%). These come from XApuEnqueueCommand → process (crates/victory-hle/src/modules/apu.rs:241, :325), which decodes each packet on the title's thread when it is queued. On the console, that work is done by dedicated audio hardware.

Suggestions:

  1. Decode on a worker thread. The API is already asynchronous: results are dequeued later and titles poll for PENDING_RESULTS or wait on the result event. Enqueue could hand the packet to a worker and return at once. The worker would fill the result and signal the event. That would take up to about 30% of this thread's time off the game.
  2. Don't allocate and zero a 46 KB buffer per packet. apu.rs:338 runs vec![0f32; MAX_FRAMES * channels] (5,760 frames × 2 channels × 4 bytes) for every packet, then copies the decoded audio out of it. Reusing one scratch buffer per stream, or decoding straight into the output when the layout allows, should remove most of that memset. Without call stacks I can't confirm that the ucrtbase memset/memcpy samples come from here, but the pattern fits.

2. One game thread spends ~26% in yield/delay while no thread is saturated

Profile B (ray tracing off, 25–40 fps, gpu_wait_ms 3.6–8.7 per 25–40 ms frame):

Thread Busy Breakdown
title-main (Opus, above) 70.1% see above
title-main 60.7% 48% game code; ~26% in Wine/libc (ntdll.so internals, getrusage, NtYieldExecution/sched_yield, NtDelayExecution); 3% xmem
title-main ×8 (workers) 27–45% ~95% game code
victory-submit 23.5% 57% xmem (victory_wc_lines 7.5%, Host::submit 6.0%, texture::digest 4.5%, reads_under_placed 4.3%, Layout::detile 3.6%); 19% radv; 9% d3d12core

No thread is near 100%, but frame rate stays at 25–40 fps and the GPU is mostly idle. The second thread's time in yields, delays, and getrusage looks like a spin/backoff wait, possibly on something xmem provides (a fence, an event, or a GPU-side result). It may also be slow on Wine/Linux: getrusage suggests a thread-times or cycle-time query (GetThreadTimes / QueryThreadCycleTime). Do you know what this thread waits on, or is there a diagnostics-build trace that would show it?

Also: #93 helped

Tested before it was merged (each PR alone on 37bb30f, RT off, same route, MangoHud frame times). With #93, hitches over 100 ms went from 12.2/min to 6.1 and 5.9/min over two drives, and the 1% low went from 11.0 to 12.4–13.5 fps. The median dropped about 5%, but the stutter improvement is clear. Thanks.

Logs and perf.data files are available on request.

**@⁠weneedbucks** on GitHub · 2026-12-02 00:13 UTC · [original](https://github.com/lobomfz/VIctory-xmem/issues/137) **System** - Intel i7-10700K (all-core 5.0 GHz, AVX offset 0), RX 9060 XT 16 GB (RDNA 4), 32 GB RAM - CachyOS (kernel 7.3), system Wine 11.23, this repo's patched Mesa and vkd3d-proton from `setup.sh` - Series S profile, 1920x1080 output, uncapped, fullscreen, `VICTORY_PAGES=0` unless stated Note: this is an Intel CPU (no sse4a/clzero/mwaitx, which VIctory emulates). As far as I know, development has been on Ryzen, so timing may differ. **Title:** CPU profile: Opus decoding (XApu) runs on a game thread; another game thread spends ~26% yielding while no thread is maxed **Build:** profiled on 37bb30f (release, `debug = "line-tables-only"`). `apu.rs` is unchanged in f7f0360, so section 1 still applies. **Settings:** `VICTORY_UPSCALER=6` (the title's own upscaler) at the time. Two flat `perf` profiles taken during city driving. Call-graph recording (`-g`) failed under Wine here, so these show where time goes, not who called what. xmem addresses were resolved against `victory.pdb` with `llvm-symbolizer`. Game addresses are offsets into the mapped game image. ### 1. Opus decoding runs synchronously on the calling game thread Profile A: ray tracing on, busiest thread (~76% busy), 60 s, 42,929 samples. Profile B: ray tracing off, all threads, 30 s, 310,516 samples. The same thread was again the busiest (70% busy). | | Profile A | Profile B | |---|---|---| | Game code | 55.4% | 59.2% | | xmem (almost all `opus_pure`) | 32.0% | 29.1% | | ucrtbase (memcpy loop + memset) | 11.6% | 11.3% | The top xmem functions in profile B are `celt::mdct::MdctLookup::backward` (4.6%), `celt::bands::quant_partition` (4.5%), `CeltDecoder::decode_impl_from_rc` (3.8%), `silk_decode_frame` (2.4%), and the SILK resamplers (`iir_fir_block` and `up2_hq`, 3.4%). These come from `XApuEnqueueCommand` → `process` (`crates/victory-hle/src/modules/apu.rs:241`, `:325`), which decodes each packet on the title's thread when it is queued. On the console, that work is done by dedicated audio hardware. Suggestions: 1. **Decode on a worker thread.** The API is already asynchronous: results are dequeued later and titles poll for `PENDING_RESULTS` or wait on the result event. Enqueue could hand the packet to a worker and return at once. The worker would fill the result and signal the event. That would take up to about 30% of this thread's time off the game. 2. **Don't allocate and zero a 46 KB buffer per packet.** `apu.rs:338` runs `vec![0f32; MAX_FRAMES * channels]` (5,760 frames × 2 channels × 4 bytes) for every packet, then copies the decoded audio out of it. Reusing one scratch buffer per stream, or decoding straight into the output when the layout allows, should remove most of that `memset`. Without call stacks I can't confirm that the ucrtbase memset/memcpy samples come from here, but the pattern fits. ### 2. One game thread spends ~26% in yield/delay while no thread is saturated Profile B (ray tracing off, 25–40 fps, `gpu_wait_ms` 3.6–8.7 per 25–40 ms frame): | Thread | Busy | Breakdown | |---|---|---| | title-main (Opus, above) | 70.1% | see above | | title-main | 60.7% | 48% game code; **~26% in Wine/libc** (`ntdll.so` internals, `getrusage`, `NtYieldExecution`/`sched_yield`, `NtDelayExecution`); 3% xmem | | title-main ×8 (workers) | 27–45% | ~95% game code | | victory-submit | 23.5% | 57% xmem (`victory_wc_lines` 7.5%, `Host::submit` 6.0%, `texture::digest` 4.5%, `reads_under_placed` 4.3%, `Layout::detile` 3.6%); 19% radv; 9% d3d12core | No thread is near 100%, but frame rate stays at 25–40 fps and the GPU is mostly idle. The second thread's time in yields, delays, and `getrusage` looks like a spin/backoff wait, possibly on something xmem provides (a fence, an event, or a GPU-side result). It may also be slow on Wine/Linux: `getrusage` suggests a thread-times or cycle-time query (`GetThreadTimes` / `QueryThreadCycleTime`). Do you know what this thread waits on, or is there a diagnostics-build trace that would show it? ### Also: #93 helped Tested before it was merged (each PR alone on 37bb30f, RT off, same route, MangoHud frame times). With #93, hitches over 100 ms went from 12.2/min to 6.1 and 5.9/min over two drives, and the 1% low went from 11.0 to 12.4–13.5 fps. The median dropped about 5%, but the stutter improvement is clear. Thanks. Logs and `perf.data` files are available on request.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 00:15:38 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 17:43 UTC · original

#455 now moves Opus decoding to dedicated worker threads, which addresses the first part of this report. It's still waiting for review/merge. The yielding thread is a separate issue.

**@⁠tommiehansen** on GitHub · 2026-12-05 17:43 UTC · [original](https://github.com/lobomfz/VIctory-xmem/issues/137#issuecomment-7442444403) #455 now moves Opus decoding to dedicated worker threads, which addresses the first part of this report. It's still waiting for review/merge. The yielding thread is a separate issue.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/lobomfz--VIctory-xmem#137
No description provided.