Formats: look up short XMA codes by their first eight bits #3671

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3671 into main
andrewpozdnakov7-jpg commented 2026-11-28 05:13:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T05:13:14Z.


XMA's variable-length codebooks now look up short codes from the first eight bits. Longer codes still use the existing sorted-table lookup. The seven prefix tables occupy 3.5 KiB total.

The existing table tests checked every code and its boundaries. I also decoded 288 generated stereo frames at all four sample rates and three transform modes, with varied quantization and scale factors. All 301,056 PCM samples, including the flush output, matched bit for bit. Across 17 alternating runs per case, median complete decode speed was 1.09–1.19x on the local Windows CPU.

The full formats library suite reported 46 passed and five ignored. Strict formats Clippy and the asset policy passed.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding this change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5536944572 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3671). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T05:13:14Z. --- XMA's variable-length codebooks now look up short codes from the first eight bits. Longer codes still use the existing sorted-table lookup. The seven prefix tables occupy 3.5 KiB total. The existing table tests checked every code and its boundaries. I also decoded 288 generated stereo frames at all four sample rates and three transform modes, with varied quantization and scale factors. All 301,056 PCM samples, including the flush output, matched bit for bit. Across 17 alternating runs per case, median complete decode speed was 1.09–1.19x on the local Windows CPU. The full formats library suite reported 46 passed and five ignored. Strict formats Clippy and the asset policy passed. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding this change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 05:16:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T05:16:46Z.


Windows CI passed at deae705, including Clippy on both build configurations and the repository test job. The generated PCM comparison and the decoder timings in the description apply to this head.

The current change is confined to XMA codebook lookup. The next step is maintainer review.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding this change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234569702 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3671#issuecomment-7234569702). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T05:16:46Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46111100621/job/140874592661) passed at `deae705`, including Clippy on both build configurations and the repository test job. The generated PCM comparison and the decoder timings in the description apply to this head. The current change is confined to XMA codebook lookup. The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding this change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 05:20:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T05:20:28Z.


I combined #3672 with the tested #3671/#3666 stack in bb19576. The overlap was in test placement, so both regression tests are present. The branch keeps both exact PR heads.

All 301,056 generated PCM samples matched the earlier stack and the combined formats suite passed 51 tests, with five ignored. Strict formats Clippy and the asset policy passed. In 17 paired runs per case, the incremental decode medians from grouped bit reads were 1.00–1.05x after short-code lookup was already in place. Several timing ranges overlapped. The 1.05–1.12x result in #3672 uses main as its baseline.

The maintainer can use the branch to review the changes together.

Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234607890 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3671#issuecomment-7234607890). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T05:20:28Z. --- I combined #3672 with the tested #3671/#3666 stack in [bb19576](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/bb19576db4256fd438fba5669bb05159e2326918). The overlap was in test placement, so both regression tests are present. The branch keeps both exact PR heads. All 301,056 generated PCM samples matched the earlier stack and the combined formats suite passed 51 tests, with five ignored. Strict formats Clippy and the asset policy passed. In 17 paired runs per case, the incremental decode medians from grouped bit reads were 1.00–1.05x after short-code lookup was already in place. Several timing ranges overlapped. The 1.05–1.12x result in #3672 uses main as its baseline. The maintainer can use the branch to review the changes together. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
Headache3318 commented 2026-11-28 09:36:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-28T09:36:09Z.


Verified head deae70520beaaf2541a4a54e355a4722e2e2b5b0 (single commit on 63bcca43) on Linux — native build, no cross needed.

Environment: Arch Linux, kernel 7.3.5-arch1-1, rustc 1.98.1, AMD Ryzen 7 9850X3D (8 cores), --locked throughout.

Suite: cargo test -p victory-formats --locked → 46 passed / 0 failed / 5 ignored (3.49 s) at head, and identical 46/0/5 (3.47 s) at base 63bcca43. Matches your report exactly.

Equivalence, mechanically: I injected the identical scratch bench (uncommitted, reverted, worktrees removed) into both trees: 200,000 reps of a sweep over every code in all seven prefix tables, decoded through read_code, with the (symbol, consumed bits, len) results folded into a checksum. All 9 alternating release-mode rounds produced the identical accumulator acc=261928000000 on head and base — every code across the whole code space selects the same symbol and consumes the same bits as the partition_point path. That's the full-table-space version of your 301,056-sample PCM claim.

The fast path is load-bearing under the existing tests: a one-token mutation inside read() only — usize::from(prefix - 1) → usize::from(prefix) — turns exactly 4 tests red: xma::tables::tests::every_entry_decodes_at_its_code_and_across_its_block, plus xma::tests::noise_frames_decode_to_a_frame_of_samples, noise_frames_with_bit_counts_past_the_data and noise_packets_walk_and_decode (42 passed / 4 failed). git checkout -- restores 46/0/5. So the prefix table is exercised end-to-end by the noise-frame decode tests, not just the tables boundary test.

Lint: cargo clippy -p victory-formats --locked --all-targets -- -D warnings clean at head.

Your speed claim reproduces on Linux: 9 alternating rounds of the in-process sweep, head median 1.3283 s vs base median 1.5825 s = 1.19× — the top of your 1.09–1.19× window, as expected since this slice times Vlc::read alone, with no IMDCT/unpacketizing to dilute it. Head rounds were tight (1.3258–1.3687 s, ≤1% spread outside one 1.37 outlier); base rounds 1.5807–1.6719 s.

Host-dependent failures, identical on base (not regressions): of the 5 ignored tests, the two throughput benches pass (bcpack::tests::bcpack_throughput, xma::tests::imdct_throughput), while three fail at identical line:col on head and base because they need external corpus env vars that aren't set on this host: bcpack::tests::reference_chunks (bcpack.rs:1592, wants VICTORY_BCPACK_TABLES), xma::tests::walks_saved_streams (xma.rs:1758) and xma::tests::matches_a_reference_decoder (xma.rs:1803) — the latter two panic on env::var(...).unwrap() → NotPresent.

AI-assisted (Hermes Agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237346072 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3671#issuecomment-7237346072). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-28T09:36:09Z. --- Verified head `deae70520beaaf2541a4a54e355a4722e2e2b5b0` (single commit on `63bcca43`) on Linux — native build, no cross needed. **Environment:** Arch Linux, kernel 7.3.5-arch1-1, rustc 1.98.1, AMD Ryzen 7 9850X3D (8 cores), `--locked` throughout. **Suite:** `cargo test -p victory-formats --locked` → **46 passed / 0 failed / 5 ignored** (3.49 s) at head, and identical 46/0/5 (3.47 s) at base `63bcca43`. Matches your report exactly. **Equivalence, mechanically:** I injected the identical scratch bench (uncommitted, reverted, worktrees removed) into both trees: 200,000 reps of a sweep over **every code in all seven prefix tables**, decoded through `read_code`, with the `(symbol, consumed bits, len)` results folded into a checksum. All 9 alternating release-mode rounds produced the identical accumulator `acc=261928000000` on head and base — every code across the whole code space selects the same symbol and consumes the same bits as the `partition_point` path. That's the full-table-space version of your 301,056-sample PCM claim. **The fast path is load-bearing under the existing tests:** a one-token mutation inside `read()` only — `usize::from(prefix - 1)` → `usize::from(prefix)` — turns exactly 4 tests red: `xma::tables::tests::every_entry_decodes_at_its_code_and_across_its_block`, plus `xma::tests::noise_frames_decode_to_a_frame_of_samples`, `noise_frames_with_bit_counts_past_the_data` and `noise_packets_walk_and_decode` (42 passed / 4 failed). `git checkout --` restores 46/0/5. So the prefix table is exercised end-to-end by the noise-frame decode tests, not just the tables boundary test. **Lint:** `cargo clippy -p victory-formats --locked --all-targets -- -D warnings` clean at head. **Your speed claim reproduces on Linux:** 9 alternating rounds of the in-process sweep, head median **1.3283 s** vs base median **1.5825 s** = **1.19×** — the top of your 1.09–1.19× window, as expected since this slice times `Vlc::read` alone, with no IMDCT/unpacketizing to dilute it. Head rounds were tight (1.3258–1.3687 s, ≤1% spread outside one 1.37 outlier); base rounds 1.5807–1.6719 s. **Host-dependent failures, identical on base (not regressions):** of the 5 ignored tests, the two throughput benches pass (`bcpack::tests::bcpack_throughput`, `xma::tests::imdct_throughput`), while three fail at identical line:col on head and base because they need external corpus env vars that aren't set on this host: `bcpack::tests::reference_chunks` (bcpack.rs:1592, wants `VICTORY_BCPACK_TABLES`), `xma::tests::walks_saved_streams` (xma.rs:1758) and `xma::tests::matches_a_reference_decoder` (xma.rs:1803) — the latter two panic on `env::var(...).unwrap()` → `NotPresent`. AI-assisted (Hermes Agent).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3671:upstream-pr/3671'
git switch 'upstream-pr/3671'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3671'
git switch 'upstream-pr/3671'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3671'
git switch 'upstream-pr/3671'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3671'
git switch 'main'
git merge --squash 'upstream-pr/3671'
git switch 'main'
git merge --ff-only 'upstream-pr/3671'
git switch 'main'
git merge 'upstream-pr/3671'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3671
No description provided.