XMA: cache IMDCT rotation tables per subframe size #172

Manually merged
github merged 1 commit from gh-pr/172/head into gh-pr/172/base 2026-11-26 03:53:16 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 01:05 UTC · original
TG0000:perf/xma-imdct-rotations → main · +296 −34 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC

Summary

Caches the pre/post rotation tables, bit-reversal order, and butterfly twiddle factors once per XMA subframe size (128, 256, and 512 samples) in imdct_half (crates/victory-formats/src/xma.rs) and replaces the per-call heap Vec work buffers with stack arrays.

Why

Previously, imdct_half recomputed sin_cos for every pre- and post-rotation on every subframe call and allocated two fresh Vec buffers per call. Precomputing those tables once per subframe size removes the repeated trig work and per-subframe heap allocations while preserving bit-for-bit identical output (each table value uses the exact same floating-point expression and butterfly recurrence as before).

Measured performance (synthetic release benchmark)

  • 3.2×–4.4× (3.7× overall) faster imdct_half across the 128/256/512 subframe sizes in MSVC release builds.
  • Note: synthetic audio-decoder microbenchmark only; end-to-end retail title frame time was not measured.

Testing

  • Added/ran unit tests in ictory-formats verifying bit-for-bit equivalence against the original implementation across all subframe sizes.
  • cargo clippy (no new warnings) and cargo run -p xtask -- policy passed.

AI-assisted (Claude Opus 5.5).

**@⁠TG0000** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/172) `TG0000:perf/xma-imdct-rotations` → `main` · +296 −34 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC ### Summary Caches the pre/post rotation tables, bit-reversal order, and butterfly twiddle factors once per XMA subframe size (128, 256, and 512 samples) in imdct_half (crates/victory-formats/src/xma.rs) and replaces the per-call heap Vec work buffers with stack arrays. ### Why Previously, imdct_half recomputed sin_cos for every pre- and post-rotation on every subframe call and allocated two fresh Vec buffers per call. Precomputing those tables once per subframe size removes the repeated trig work and per-subframe heap allocations while preserving bit-for-bit identical output (each table value uses the exact same floating-point expression and butterfly recurrence as before). ### Measured performance (synthetic release benchmark) - ~**3.2×–4.4×** (~**3.7×** overall) faster imdct_half across the 128/256/512 subframe sizes in MSVC release builds. - Note: synthetic audio-decoder microbenchmark only; end-to-end retail title frame time was not measured. ### Testing - Added/ran unit tests in ictory-formats verifying bit-for-bit equivalence against the original implementation across all subframe sizes. - cargo clippy (no new warnings) and cargo run -p xtask -- policy passed. *AI-assisted (Claude Opus 5.5).*
imdct_half worked out every pre- and post-rotation with sin_cos on each
call (n of them per subframe) and ran its FFT on two fresh Vecs. The
rotations, the bit-reversed order and the butterfly rotations now come
from a table built once for 128, 256 and 512 samples; the work buffers
live on the stack. Every value is computed with the same expression (the
butterflies with the same running product), so the output is bit for
bit what it was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:15 +00:00
github manually merged commit 4eb0898b3c into gh-pr/172/base 2026-11-26 03:53:16 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:23 UTC · original

Tested 4eb0898 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-formats: 22 passed, 0 failed, 4 ignored (2 test binaries), including the 3 tests this PR adds.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/172#issuecomment-7119051347) Tested `4eb0898` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-formats`: **22 passed, 0 failed, 4 ignored** (2 test binaries), including the 3 tests this PR adds. No game data used.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:20 UTC · original

Automated triage for the maintainers.

Merge candidate. imdct_half in crates/victory-formats/src/xma.rs now builds the pre/post rotations, bit-reversal order and butterfly twiddles once per subframe size (128/256/512, in a OnceLock like the existing windows()) and uses a stack buffer sized by FRAME_SAMPLES instead of two Vecs per call. Each table entry uses the same expression and the same per-stage running product as the old per-call code; other sizes still build tables on the spot, and tabled_imdct_gives_the_same_bits compares the output bit for bit against the old transform for n = 2…2048. The ~3.7x speed-up is for the transform alone; no in-title measurement.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/172#issuecomment-7148412127) <!-- victory-triage v1 head=4eb0898b3cbd6d0bbbffad540aca5d7e3531ac58 verdict=merge-candidate at=2026-11-25T00:18:15Z --> Automated triage for the maintainers. **Merge candidate.** `imdct_half` in `crates/victory-formats/src/xma.rs` now builds the pre/post rotations, bit-reversal order and butterfly twiddles once per subframe size (128/256/512, in a `OnceLock` like the existing `windows()`) and uses a stack buffer sized by `FRAME_SAMPLES` instead of two `Vec`s per call. Each table entry uses the same expression and the same per-stage running product as the old per-call code; other sizes still build tables on the spot, and `tabled_imdct_gives_the_same_bits` compares the output bit for bit against the old transform for n = 2…2048. The ~3.7x speed-up is for the transform alone; no in-title measurement. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
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!172
No description provided.