CPU profile: Opus decoding (XApu) runs on a game thread; another game thread spends ~26% yielding while no thread is maxed #137
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/lobomfz--VIctory-xmem#137
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?
@weneedbucks on GitHub · 2026-12-02 00:13 UTC · original
System
setup.shVICTORY_PAGES=0unless statedNote: 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.rsis unchanged inf7f0360, so section 1 still applies.Settings:
VICTORY_UPSCALER=6(the title's own upscaler) at the time.Two flat
perfprofiles 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 againstvictory.pdbwithllvm-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).
opus_pure)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_blockandup2_hq, 3.4%). These come fromXApuEnqueueCommand→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:
PENDING_RESULTSor 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.apu.rs:338runsvec 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 thatmemset. 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_ms3.6–8.7 per 25–40 ms frame):ntdll.sointernals,getrusage,NtYieldExecution/sched_yield,NtDelayExecution); 3% xmemvictory_wc_lines7.5%,Host::submit6.0%,texture::digest4.5%,reads_under_placed4.3%,Layout::detile3.6%); 19% radv; 9% d3d12coreNo 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
getrusagelooks 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:getrusagesuggests 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.datafiles are available on request.@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.