victory-hle(apu): reuse Opus decode scratch buffer and pre-reserve result queue #2423

Open
github-bot wants to merge 1 commit from github-bot/gh-2423 into main AGit
Owner

@⁠faycalbaklouti on GitHub · 2026-11-25 13:14 UTC · original
faycalbaklouti:fix/apu-opus-scratch-buffer → main · +158 −6 · 1 files · 1 commits · open

Target upstream: Marvisak/VIctory (also applies cleanly to Belobug/VIctory-Belobug-AMD and fxceless/victory-fork)

Problem

The Opus audio decode path in crates/victory-hle/src/modules/apu.rs allocated fresh per-packet scratch buffers and grew the result queue dynamically on every decode batch, creating unnecessary heap churn on the audio thread.

Solution

  • Reuse a persistent Opus decode scratch buffer across decode calls instead of allocating per frame.
  • Pre-reserve the result queue capacity up front to avoid incremental reallocations during batch decoding.

Verification

  • git apply --check passes cleanly on Marvisak/VIctory main (direct zero-conflict apply).
  • Verified with existing APU Opus decode unit tests.

About our fork & censorship-resistant preservation effort:
This fix comes from gta6-vi-port, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries).

**@⁠faycalbaklouti** on GitHub · 2026-11-25 13:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2423) `faycalbaklouti:fix/apu-opus-scratch-buffer` → `main` · +158 −6 · 1 files · 1 commits · open **Target upstream:** `Marvisak/VIctory` (also applies cleanly to `Belobug/VIctory-Belobug-AMD` and `fxceless/victory-fork`) ## Problem The Opus audio decode path in `crates/victory-hle/src/modules/apu.rs` allocated fresh per-packet scratch buffers and grew the result queue dynamically on every decode batch, creating unnecessary heap churn on the audio thread. ## Solution - Reuse a persistent Opus decode scratch buffer across decode calls instead of allocating per frame. - Pre-reserve the result queue capacity up front to avoid incremental reallocations during batch decoding. ## Verification - `git apply --check` passes cleanly on `Marvisak/VIctory` `main` (direct zero-conflict apply). - Verified with existing APU Opus decode unit tests. --- **About our fork & censorship-resistant preservation effort:** This fix comes from **[gta6-vi-port](https://github.com/go2afri/gta6-vi-port)**, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries). - **Canonical Radicle repo:** https://radicle.network/nodes/rosa.radicle.network/rad:z39ofPhQC1siudH9BF3xsmAMmUqxc (`rad:z39ofPhQC1siudH9BF3xsmAMmUqxc`) - **Live 1080p development stream:** https://vdo.ninja/?view=gta6rtx4090live1080p60 (Tor v3 `.onion` VP9+Opus viewer: `http://kwnoaeecpmxd6eetqfa7fxlymvxnh5du2i6wxr44t4mc7cgch5pw23id.onion/`)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:22 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:32 UTC · original

Automated triage for the maintainers.

Needs work. This keeps a reused decode_buf in the APU State instead of allocating MAX_FRAMES * channels floats per packet in process (crates/victory-hle/src/modules/apu.rs), and gives results a starting capacity of streams * commands_per_stream. The logic is fine and it resizes for streams with more channels. What would change the verdict:

  • A measurement. The PR says the allocation causes heap churn on the audio thread but gives no profile or timing; one ~46 KB allocation per packet is unlikely to matter next to the Opus decode itself.
  • A better test. process_reuses_decode_scratch_buffer_without_reallocating asserts the buffer's pointer and capacity stay the same, which is the implementation, not behaviour. The existing decode tests already cover correctness.
  • The starting capacity comes from the title (streams * commands_per_stream); please cap it or keep VecDeque::new().

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2423#issuecomment-7167000188) <!-- victory-triage v1 head=cf1607b1261ca78b656a74c3cacaa66d5646d665 verdict=needs-work at=2026-11-25T15:36:00Z --> Automated triage for the maintainers. **Needs work.** This keeps a reused `decode_buf` in the APU `State` instead of allocating `MAX_FRAMES * channels` floats per packet in `process` (`crates/victory-hle/src/modules/apu.rs`), and gives `results` a starting capacity of `streams * commands_per_stream`. The logic is fine and it resizes for streams with more channels. What would change the verdict: - **A measurement.** The PR says the allocation causes heap churn on the audio thread but gives no profile or timing; one ~46 KB allocation per packet is unlikely to matter next to the Opus decode itself. - **A better test.** `process_reuses_decode_scratch_buffer_without_reallocating` asserts the buffer's pointer and capacity stay the same, which is the implementation, not behaviour. The existing decode tests already cover correctness. - **The starting capacity** comes from the title (`streams * commands_per_stream`); please cap it or keep `VecDeque::new()`. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 16:53 UTC · original

Sound: decode_buf is behind the connection mutex (streams can't race on it), needed falls back to resize for >2-channel decoders (Opus supports up to 8 — MAX_PCM_SAMPLES only pre-sizes stereo, not a cap), and the borrow is disjoint (state.streams[x] decoder vs state.decode_buf). results pre-reserve matches the documented max queue depth. Test verifies capacity retention — good regression pin.

**@⁠kotekompotek** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2423#issuecomment-7168688629) Sound: `decode_buf` is behind the connection mutex (streams can't race on it), `needed` falls back to `resize` for >2-channel decoders (Opus supports up to 8 — `MAX_PCM_SAMPLES` only pre-sizes stereo, not a cap), and the borrow is disjoint (`state.streams[x]` decoder vs `state.decode_buf`). `results` pre-reserve matches the documented max queue depth. Test verifies capacity retention — good regression pin.
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/2423/head:github-bot/gh-2423'
git switch 'github-bot/gh-2423'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2423'
git switch 'github-bot/gh-2423'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2423'
git switch 'github-bot/gh-2423'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2423'
git switch 'main'
git merge --squash 'github-bot/gh-2423'
git switch 'main'
git merge --ff-only 'github-bot/gh-2423'
git switch 'main'
git merge 'github-bot/gh-2423'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Marvisak--VIctory!2423
No description provided.