BCPack: find a slot's bucket from a window table #93

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

@⁠TG0000 on GitHub · 2026-11-24 00:24 UTC · original
TG0000:perf/bcpack-bucket-lookup → main · +223 −28 · 1 files · 1 commits · merged 2026-11-24 08:47 UTC

The BCPack decoder (crates/victory-formats/src/bcpack.rs, the DirectStorage texture unpack path) spends almost all of its time in Lane::step, one rANS symbol at a time. This PR makes the per-symbol work cheaper. The output stays the same.

What changes

  • Bucket lookup: each symbol used to scan all of its model's bucket starts. Tables now keeps one byte per 256-slot window per model (32 KiB, boxed, built in Tables::parse): the bucket of the window's first slot. bucket_of starts there and steps over the few buckets that begin inside the window. start gets one more 65536 sentinel, so the step loop needs no length check.
  • Symbol arithmetic: the symbol, frequency and remainder come straight from the bucket and the existing exact reciprocal. The old code rebuilt the frequency and cumulative start from the symbol (leading_zeros, a multiply, a mask).
  • Lane loop: the record offset is carried along, instead of computing pos / per * stride + pos % per (a division by a runtime value) for every symbol.

Measured

Synthetic streams with the synthetic test tables. No game data. Release build, one core, 16384 blocks, median of 3 runs, before and after on the same machine:

format before after throughput
BC1 177 ns/block 128 ns/block +38%
BC4 184 ns/block 128 ns/block +44%
BC7 591 ns/block 452 ns/block +31%

To reproduce: cargo test --release -p victory-formats bcpack_throughput -- --ignored --nocapture

Tests

  • bucket_lookup_matches_a_scan_of_the_starts: the window lookup against the old scan, for every slot of every model, on the shipped tables, on the uniform synthetic tables and on tables with one-slot buckets.
  • payload_step_matches_the_reference_decode: a payload Lane::step against the first version's arithmetic (scan plus division), on the shipped tables and the synthetic ones, for every model and slot at three state heights.
  • every_layout_round_trips_through_the_lanes: all six format lane layouts at 1, 2, 17, 300 and 1000 blocks, with short and long fragments.
  • bcpack_throughput (ignored): the benchmark above.

What ran: cargo test --workspace and cargo xtask policy pass, and clippy --workspace --all-targets reports nothing new. I didn't run the ignored reference_chunks test, because it needs reference chunks from outside the repository. This is CPU-only code, so it wasn't run on a GPU or against the game.

It touches only bcpack.rs, which no open PR touches.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 00:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/93) `TG0000:perf/bcpack-bucket-lookup` → `main` · +223 −28 · 1 files · 1 commits · merged 2026-11-24 08:47 UTC The BCPack decoder (`crates/victory-formats/src/bcpack.rs`, the DirectStorage texture unpack path) spends almost all of its time in `Lane::step`, one rANS symbol at a time. This PR makes the per-symbol work cheaper. The output stays the same. ## What changes - **Bucket lookup**: each symbol used to scan all of its model's bucket starts. `Tables` now keeps one byte per 256-slot window per model (32 KiB, boxed, built in `Tables::parse`): the bucket of the window's first slot. `bucket_of` starts there and steps over the few buckets that begin inside the window. `start` gets one more 65536 sentinel, so the step loop needs no length check. - **Symbol arithmetic**: the symbol, frequency and remainder come straight from the bucket and the existing exact reciprocal. The old code rebuilt the frequency and cumulative start from the symbol (`leading_zeros`, a multiply, a mask). - **Lane loop**: the record offset is carried along, instead of computing `pos / per * stride + pos % per` (a division by a runtime value) for every symbol. ## Measured Synthetic streams with the synthetic test tables. No game data. Release build, one core, 16384 blocks, median of 3 runs, before and after on the same machine: | format | before | after | throughput | |---|---|---|---| | BC1 | 177 ns/block | 128 ns/block | +38% | | BC4 | 184 ns/block | 128 ns/block | +44% | | BC7 | 591 ns/block | 452 ns/block | +31% | To reproduce: `cargo test --release -p victory-formats bcpack_throughput -- --ignored --nocapture` ## Tests - `bucket_lookup_matches_a_scan_of_the_starts`: the window lookup against the old scan, for every slot of every model, on the shipped tables, on the uniform synthetic tables and on tables with one-slot buckets. - `payload_step_matches_the_reference_decode`: a payload `Lane::step` against the first version's arithmetic (scan plus division), on the shipped tables and the synthetic ones, for every model and slot at three state heights. - `every_layout_round_trips_through_the_lanes`: all six format lane layouts at 1, 2, 17, 300 and 1000 blocks, with short and long fragments. - `bcpack_throughput` (ignored): the benchmark above. What ran: `cargo test --workspace` and `cargo xtask policy` pass, and `clippy --workspace --all-targets` reports nothing new. I didn't run the ignored `reference_chunks` test, because it needs reference chunks from outside the repository. This is CPU-only code, so it wasn't run on a GPU or against the game. It touches only `bcpack.rs`, which no open PR touches. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each rANS symbol scanned all of its model's bucket starts to find the slot's
bucket, then rebuilt the symbol's frequency and start from the symbol. A
per-model table of the bucket at each 256-slot window's first slot now starts
the search, which steps over the few buckets that begin inside the window; the
symbol, frequency and remainder come straight from that bucket. The lane loop
also keeps the record offset instead of dividing by the symbols per block on
every symbol.

Synthetic streams, release, one core (median of 3 runs, 16384 blocks):
BC1 177 -> 128 ns/block, BC4 184 -> 128, BC7 591 -> 452.

Tests: the window lookup against the scan for every slot of every model
(shipped tables, uniform tables, one-slot buckets); a payload step against the
first version's arithmetic on the shipped tables; every format's lane layout
round trips at 1 to 1000 blocks; an ignored throughput benchmark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:58 +00:00
github manually merged commit 3e982f7ec4 into gh-pr/93/base 2026-11-26 03:50:00 +00:00
Author
Owner

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

Tested 3e982f7: pass.

  • Tested on Arch Linux x86_64, rustc 1.98.1, cargo test -p victory-formats: 20 passed, 0 failed, 4 ignored, including the 4 tests this PR adds.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/93#issuecomment-7118861040) Tested `3e982f7`: **pass**. - Tested on **Arch Linux x86_64, rustc 1.98.1**, `cargo test -p victory-formats`: **20 passed, 0 failed, 4 ignored**, including the 4 tests this PR adds. No game data used.
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!93
No description provided.