perf(formats): share XMA2 scale factor tables across voices #661

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

@⁠tevanc14 on GitHub · 2026-12-06 02:06 UTC · original
tevanc14:perf/xma-scale-factor-tables → main · +71 −40 · 1 files · 1 commits · open

Every active XMA2 voice constructs a decoder. The scale factor tables depend only on the normalized sample rate, but each decoder currently rebuilds and stores a copy. Compute the four layouts at compile time and share the immutable tables across decoders.

Benchmark

Compared 8c4e663 with d0d81fb on Linux, Ryzen 5 7600X, Rust 1.98.1. Both builds ran the same harness with the production codec and the project's synthetic valid XMA2 stream generator. Rates were 24, 32, 44.1, and 48 kHz, with mono and stereo cases. The harness timed decoder construction followed by decoding one, eight, or 64 frames per voice, and measured reuse separately. Input generation and PCM allocation were outside timing. Built with rustc --edition 2024 --test -O -C codegen-units=1 -C lto=thin -C target-cpu=x86-64-v3 and ran pinned with taskset -c 4. Six trials per build, balanced in ABBA/BAAB/ABBA order.

Workload Main median PR median Time change vs. main
Initialize and decode first frame 5.155 µs/voice 4.658 µs/voice −9.64%
Initialize and decode eight frames 38.286 µs/voice 37.421 µs/voice −2.26%
Initialize and decode 64 frames 356.942 µs/voice 354.819 µs/voice −0.59%
Reuse an initialized decoder 5.022 µs/frame 4.990 µs/frame −0.63%

First-frame samples (µs/voice, paired in execution order):

Pair Main PR
1 5.212 4.939
2 5.134 5.294
3 5.298 4.658
4 5.153 4.647
5 5.157 4.633
6 5.144 4.658

First-frame time improved in five of six pairs. The steady decoding difference was within run-to-run variation. Decoder size on x86-64 fell from 14,304 to 11,480 bytes, saving 2,824 bytes per decoder and adding 11,328 bytes of shared read-only tables. This is a codec benchmark using generated audio. Game audio latency and FPS were outside its scope.

Checks

  • N/A for switch and settings docs. Existing rate buckets and decoded output are preserved, and there is no new user-facing behavior.
  • Scope is limited to XMA2 band tables and their call sites.
  • The differential harness compared both builds byte for byte across generated inputs, decoded PCM including flush, and table entries for nine rates covering bucket boundaries. Performance and object size distinguish the change. Existing decoder tests cover the decode path, so the benchmark supplies the regression evidence for this representation change.
  • Queue checked. #629 also edits the decoder for overlap carry and resume, independently of this change. Closed #362 and #294 cover Huffman lookups.
  • cargo xtask policy passed for 370 files.

Also ran cargo test --locked --release -p victory-formats (66 passed, nine ignored) on Linux and ./build.sh check for the Windows build. Windows was compile-checked.

**@⁠tevanc14** on GitHub · 2026-12-06 02:06 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/661) `tevanc14:perf/xma-scale-factor-tables` → `main` · +71 −40 · 1 files · 1 commits · open Every active XMA2 voice constructs a decoder. The scale factor tables depend only on the normalized sample rate, but each decoder currently rebuilds and stores a copy. Compute the four layouts at compile time and share the immutable tables across decoders. ### Benchmark Compared `8c4e663` with `d0d81fb` on Linux, Ryzen 5 7600X, Rust 1.98.1. Both builds ran the same harness with the production codec and the project's synthetic valid XMA2 stream generator. Rates were 24, 32, 44.1, and 48 kHz, with mono and stereo cases. The harness timed decoder construction followed by decoding one, eight, or 64 frames per voice, and measured reuse separately. Input generation and PCM allocation were outside timing. Built with `rustc --edition 2024 --test -O -C codegen-units=1 -C lto=thin -C target-cpu=x86-64-v3` and ran pinned with `taskset -c 4`. Six trials per build, balanced in ABBA/BAAB/ABBA order. | Workload | Main median | PR median | Time change vs. main | | --- | ---: | ---: | ---: | | Initialize and decode first frame | 5.155 µs/voice | 4.658 µs/voice | −9.64% | | Initialize and decode eight frames | 38.286 µs/voice | 37.421 µs/voice | −2.26% | | Initialize and decode 64 frames | 356.942 µs/voice | 354.819 µs/voice | −0.59% | | Reuse an initialized decoder | 5.022 µs/frame | 4.990 µs/frame | −0.63% | First-frame samples (µs/voice, paired in execution order): | Pair | Main | PR | | --- | ---: | ---: | | 1 | 5.212 | 4.939 | | 2 | 5.134 | 5.294 | | 3 | 5.298 | 4.658 | | 4 | 5.153 | 4.647 | | 5 | 5.157 | 4.633 | | 6 | 5.144 | 4.658 | First-frame time improved in five of six pairs. The steady decoding difference was within run-to-run variation. Decoder size on x86-64 fell from 14,304 to 11,480 bytes, saving 2,824 bytes per decoder and adding 11,328 bytes of shared read-only tables. This is a codec benchmark using generated audio. Game audio latency and FPS were outside its scope. ### Checks - N/A for switch and settings docs. Existing rate buckets and decoded output are preserved, and there is no new user-facing behavior. - [x] Scope is limited to XMA2 band tables and their call sites. - [x] The differential harness compared both builds byte for byte across generated inputs, decoded PCM including flush, and table entries for nine rates covering bucket boundaries. Performance and object size distinguish the change. Existing decoder tests cover the decode path, so the benchmark supplies the regression evidence for this representation change. - [x] Queue checked. #629 also edits the decoder for overlap carry and resume, independently of this change. Closed #362 and #294 cover Huffman lookups. - [x] `cargo xtask policy` passed for 370 files. Also ran `cargo test --locked --release -p victory-formats` (66 passed, nine ignored) on Linux and `./build.sh check` for the Windows build. Windows was compile-checked.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 02:11:54 +00:00
This pull request can be merged automatically.
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/661/head:github-bot/gh-661'
git switch 'github-bot/gh-661'

Merge

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