XMA decoder: lock only voices that are on, sleep while none is #23

Open
github-bot wants to merge 1 commit from github-bot/gh-23 into a-publier AGit
Owner

@⁠romainhedouin on GitHub · 2026-11-25 12:28 UTC · original
romainhedouin:perf/xma-pump-idle → a-publier · +30 −9 · 1 files · 1 commits · open

The audio decoder thread woke up every 2 ms and locked every voice, including voices that are switched off. Now it skips switched-off voices without locking them, and sleeps until woken while no voice is on. Switching a voice on or giving it data already wakes the thread, so nothing is missed. Decoding of voices that are on is unchanged.

Before After
Voice locks per pass (C voices, E on) C E
Wake-ups per second with no voice on 500 0
Voice locks per second, 512 voices, 8 on up to 256,000 up to 4,000

Counts from the code, not timings. Type-checked for Windows (cargo clippy -p victory-hle --target x86_64-pc-windows-msvc, with and without --all-features, no new warnings); not run.

🤖 Generated with Claude Code

**@⁠romainhedouin** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/23) `romainhedouin:perf/xma-pump-idle` → `a-publier` · +30 −9 · 1 files · 1 commits · open The audio decoder thread woke up every 2 ms and locked every voice, including voices that are switched off. Now it skips switched-off voices without locking them, and sleeps until woken while no voice is on. Switching a voice on or giving it data already wakes the thread, so nothing is missed. Decoding of voices that are on is unchanged. | | Before | After | |---|---|---| | Voice locks per pass (C voices, E on) | C | E | | Wake-ups per second with no voice on | 500 | 0 | | Voice locks per second, 512 voices, 8 on | up to 256,000 | up to 4,000 | Counts from the code, not timings. Type-checked for Windows (`cargo clippy -p victory-hle --target x86_64-pc-windows-msvc`, with and without `--all-features`, no new warnings); not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:33:18 +00:00
Author
Owner

@⁠Ekabusto on GitHub · 2026-11-25 12:47 UTC · original

Checked locally: builds. cargo test -p victory-hle --lib shows only the five xmem failures that are already on main (#2 and #8); the XMA tests pass. No conflicts with main or the other open PRs.

The wake-up logic holds: enable is the only place that makes a voice Some, and it stores enabled = true under the voice's lock before wake_decoder() unparks the thread. An unpark before the park() leaves the token set, so a voice enabled during a pass that found none is not missed. disable clears the flag under the same lock, and enabled is rebuilt together with voices in AcpHalAllocateShapeContexts. Looks good to me.

Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).

**@⁠Ekabusto** on GitHub · 2026-11-25 12:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/23#issuecomment-7162865880) Checked locally: builds. `cargo test -p victory-hle --lib` shows only the five `xmem` failures that are already on `main` (#2 and #8); the XMA tests pass. No conflicts with `main` or the other open PRs. The wake-up logic holds: `enable` is the only place that makes a voice `Some`, and it stores `enabled = true` under the voice's lock before `wake_decoder()` unparks the thread. An unpark before the `park()` leaves the token set, so a voice enabled during a pass that found none is not missed. `disable` clears the flag under the same lock, and `enabled` is rebuilt together with `voices` in `AcpHalAllocateShapeContexts`. Looks good to me. Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).
github-bot changed target branch from main to a-publier 2026-11-27 01:00:08 +00:00
github-bot force-pushed github-bot/gh-23 from 63ebaa237c to ffc0cb40c4 2026-11-27 01:00:09 +00:00 Compare
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:47 UTC · original · reviewed

AI-assisted static review (ChatGPT); I inspected the wake path but did not run tests.

**@⁠gut0to** on GitHub · 2026-11-27 14:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/23#pullrequestreview-6089871777) · **reviewed** AI-assisted static review (ChatGPT); I inspected the wake path but did not run tests.
@ -711,0 +724,4 @@
let active = xma().pump();
if active == 0 {
// Enabling a voice wakes the thread.
std::thread::park();
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:47 UTC · original

Could the idle-worker liveness contract get a deterministic test? The zero-active path now parks indefinitely, so enabling a voice must wake the worker both when it is already parked and when the wake lands after pump() returns zero but before park(). A barrier or test seam around that boundary could verify both interleavings without relying on the former 2 ms timeout.

**@⁠gut0to** on GitHub · 2026-11-27 14:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/23#discussion_r4720762372) Could the idle-worker liveness contract get a deterministic test? The zero-active path now parks indefinitely, so enabling a voice must wake the worker both when it is already parked and when the wake lands after `pump()` returns zero but before `park()`. A barrier or test seam around that boundary could verify both interleavings without relying on the former 2 ms timeout.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/23/head:github-bot/gh-23'
git switch 'github-bot/gh-23'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-23'
git switch 'github-bot/gh-23'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-23'
git switch 'github-bot/gh-23'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-23'
git switch 'a-publier'
git merge --squash 'github-bot/gh-23'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-23'
git switch 'a-publier'
git merge 'github-bot/gh-23'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.