XMA: accelerate VLC decoding with an eight-bit prefix lookup #364
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by pedrofort on 2026-11-24T02:37:01Z.
<head></head>
Motivation
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.
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:28:13Z.
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
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:50:44Z.
Review: APPROVED
Tested
e503756on Windows 11, RTX 5070, MSVC:cargo test -p victory-formats21 passed, andcargo clippy -p victory-formats --all-targetsis clean.Decoders, 8 to 608 bytes, random bit lengths) throughDecoder::decodeon mercuryVM/VIctory main and on this head. Both decoders give the same Ok and Err split (2,102 succeed, 17,898 fail), the same 15,391,232 output samples, and an identical hash over every sample. So the eight-bit prefix table is a pure speedup, with no change on the accept or error paths, malformed streams included.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:27:46Z.
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
Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T05:54:08Z.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.