Skip to content

CPU: cache XMA transform rotations and avoid scratch allocations - #122

Open
yefan911 wants to merge 1 commit into
DexNom:mainfrom
yefan911:perf/cpu-xma-transform
Open

yefan911 wants to merge 1 commit into
DexNom:mainfrom
yefan911:perf/cpu-xma-transform

Conversation

@yefan911

Copy link
Copy Markdown

XMA audio decoding currently recalculates fixed sine/cosine rotations and allocates two FFT scratch buffers for every channel and subframe. Cache the rotations for the three supported block sizes and use 4 KiB of bounded stack scratch, preserving the existing FFT arithmetic and precision.

The rotation cache is shared across streams and occupies about 14 KiB. After initialization, the transform performs no heap allocations. This change also adds silence/impulse/scaling coverage, an ignored CPU microbenchmark, and reproduction notes in docs/cpu-audio.md.

CPU-only measurements

Compared with 8114ff7 on an ARM64 Linux development host using Rust 1.98.1 and the release profile:

Samples per transform Before After Less transform time
128 4.138 microseconds 2.148 microseconds 48.1%
256 8.160 microseconds 3.170 microseconds 61.1%
512 22.754 microseconds 6.867 microseconds 69.8%

Each figure is the median of three interleaved executions per version; each execution reports the median of five batches of 10,000 warmed-up transforms. These are transform microbenchmarks. Whole-decoder CPU usage, Windows runtime performance, and gameplay FPS have not been measured. No GPU execution was used.

Validation

  • Debug and release format-library suites: 27 passed, 5 ignored in each configuration. The ignored tests comprise two microbenchmarks and three external-fixture tests; the new transform microbenchmark was executed separately.
  • A supplemental local harness compared the original and optimized transform bodies on 256 inputs per block size at four scales. All 917,504 output samples matched bit for bit. Allocation counting measured 2 -> 0 heap allocations per warmed-up transform.
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings passed.
  • cargo check -p victory-formats --target x86_64-pc-windows-msvc --tests --locked passed; this is cross-compilation, not a Windows runtime test.
  • git diff --check passed.

The existing verified BCPack tables were supplied locally for the format-library build. No binary fixture is included in the patch. External-fixture audio reference tests were not run.

@andrewDoing

Copy link
Copy Markdown

Independent Windows x64/MSVC check at f19d3dd on Ryzen 7 5700X3D: the release victory-formats suite passed (27 passed, 5 ignored). Extracted base 8114ff7 and head transform bodies matched bit for bit on 896,000 synthetic output samples across all three sizes, three scales and five input patterns. Seven interleaved batches of 5,000 warmed transforms gave median per-transform times of 1.836 → 0.713 µs (128 samples), 3.710 → 1.531 µs (256) and 7.633 → 3.206 µs (512). This measures the synthetic transform only, not whole-decoder behavior or gameplay.

This broader change covers the cached-rotation work in my narrower #113, which I have closed to reduce duplicate review work. Verification was AI-assisted with GPT-6.2 Astra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants