XMA: accelerate VLC decoding with an eight-bit prefix lookup #364
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!364
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-364"
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?
@pedrofort on GitHub · 2026-11-24 02:37 UTC · original
<head></head>pedrofort:optimize-xma-vlc→main· +207 −2 · 1 files · 1 commits · openMotivation
XMA variable-length code decoding currently performs a binary search over the entire VLC table for every decoded symbol.
Implementation
Precompute candidate ranges for all 256 possible eight-bit prefixes during VLC table initialization.
Directly resolve prefixes with a single candidate.
Restrict binary searches to the corresponding candidate range otherwise.
Preserve symbol selection and bit consumption.
No new dependencies or unsafe code.
The additional lookup tables consume approximately 28 KiB across the seven codebooks on 64-bit targets.
Performance
Synthetic release microbenchmarks on Apple M5, macOS arm64, Rust 1.98.1, base commit
Session | All codes | Short codes -- | -- | -- 1 | 2.206x | 7.829x 2 | 2.058x | 7.877x 3 | 2.013x | 7.728x Median speedup | 2.058x | 7.829xd2a4bae.Each measurement processes 1,048,576 symbols. Each session includes warm-up and five measurements with alternating execution order.
All benchmark checksums matched.
The original implementation was also benchmarked against itself as a baseline control, producing speedups of 0.997x and 0.986x.
These are synthetic VLC microbenchmarks, not end-to-end audio decoding or game performance measurements.
Correctness and validation
Equivalence verified across all seven VLC codebooks, code boundaries, prefix boundaries, deterministic random inputs and all eight bit alignments.
Decoded symbols and consumed bit counts match the original implementation.
Full formats suite: 21 passed, 0 failed, 4 ignored.
Clippy with
-D warnings: clean.Asset policy: 151 files OK.
git diff --check: clean.Reproduction
cargo test --locked --release -p victory-formats --lib vlc_prefix_benchmark -- --ignored --nocaptureAll benchmark inputs are synthetic. No game assets were used.
Independent performance measurements on Windows x86-64 would be welcome.
AI-assisted implementation and test preparation (ChatGPT), with tests and benchmarks executed locally on Apple Silicon.
@jeremygold02 on GitHub · 2026-11-24 04:28 UTC · original
Tested PR #364 at head
e503756597cafb3ac6c259ec82458fa5c61215aa(state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged ate503756597cafb3ac6c259ec82458fa5c61215aa.cargo test --locked -p victory-formats vlc_prefix_matches_binary_search— passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 24 filtered out; finished in 0.04s ); cases: xma::tests::vlc_prefix_matches_binary_search.Behavior covered: Checks prefix-table decoding matches the binary-search reference across all seven VLC books, prefix/code boundaries, random probes and bit alignments.
Code: crates/victory-formats/src/xma.rs
@Marvisak on GitHub · 2026-11-25 00:27 UTC · original
Automated triage for the maintainers.
Needs work (small). The change in
Vlc::new/Vlc::read(crates/victory-formats/src/xma.rs) looks correct: each 8-bit prefix maps to the range [last code <= prefix<<24, first code > prefix<<24|0xffffff), and sincecodes[0].0 == 0the- 1cannot underflow;vlc_prefix_matches_binary_searchis a good equivalence test. To merge: runcargo fmton the file (stray blank line afteruse super::*;, wrapping rustfmt would change); drop the ~120-line ignoredvlc_prefix_benchmarkor cut it to a few lines (figures belong in the description); and ideally give one end-to-end number, e.g. decoding a synthetic XMA stream, to show the lookup is worth 28 KiB of tables.CI: no check runs on the head commit.
Generated by Claude Code
@passerbyyhx on GitHub · 2026-11-26 05:54 UTC · original
On Windows x86-64, the full decoder ran 1.244× faster (median of 12 paired parent/PR timings) on a synthetic non-silent stream made entirely of short VLC codes. Both builds produced the same 16,896 PCM bytes, including 8,446 nonzero samples out of 8,448.
I compared parent
d2a4bae1and PRe5037565on an i9-14900HX with release Rust 1.98.1/MSVC. Each stream constructs a decoder, reads 16 mono 48 kHz XMA2 frames via the public packet/frame and decode APIs, and flushes it. A separate untimed count verified 368 one-bit scale codes and 2,048 six-bit vector codes per stream.Each arm warmed up for 16 streams and then decoded 32,768 frames on the same logical CPU. I alternated the running order every pair. Median elapsed times were 470.526 ms (parent) and 380.160 ms (PR). The PR was faster in all 12 pairs, with individual ratios from 1.061× to 1.523×. CPU frequency and background load were unmeasured, and other code-length distributions may produce a different result.
The PR's original symbol benchmark, over three processes, gave median speed ratios of 6.966× for short codes and 1.033× for the all-code corpus. These are isolated lookup timings. Reproduction scripts, full measurements and PCM checksum.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.