Formats: eliminate BCPack per-call allocations and optimize streaming decode #703
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/703"
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 wbkepler on 2026-11-24T07:07:03Z.
Summary
Eliminates per-call heap allocations and optimizes streaming BCPack decompression in
crates/victory-formats/src/bcpack.rs(0 unsafe,Tablesuntouched):bcpack::Workspacebacked by a re-entrancy-safe thread-localWorkspaceinbcpack::decode.recordsbuffer and two-pass decode with const-genericlanes_stream<N, PER, STRIDE>streaming stack records straight into block decoders.Lane::stepwith cold control-phase split, branchless 8-way bucket lookup, and direct remainder math.BC6Hwide loops with compile-time LUTs (SPREAD4,SPREAD8,NIBBLES_EVEN_FIRST), precomputed plain-format masks, and 16-bitanchor_maskinbc7_pack(+40–52% single-core release throughput across BC1/BC4/BC6H/BC7).Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passed (victory-formats: 23/23 including exhaustive 128x65536 rANS equivalence, all-6-format workspace reuse, and LUT equivalence tests)cargo xtask policy— passed (151 files ok)Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:09:39Z.
Review: APPROVED
Tested on Windows 11 MSVC (rustc 1.98.1):
Stack-streamed decode and thread-local workspace reuse eliminate per-texture heap allocations during asset decompression without modifying existing format tables.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T08:04:00Z.
Review: APPROVED
cargo test -p victory-formats --lockedon macOS 26 arm64, rustc 1.98.1: head alone 23 passed, and after merging current main (7374bfb) still 23 passed / 0 failed (+3 vs main's 20 — the new BCPack coverage runs ungated). Approving.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:04:49Z.
Review: COMMENTED
Rebase note: this no longer merges cleanly with current main (
8e79c80) — conflict incrates/victory-formats/src/bcpack.rs. #93 (perf/bcpack-bucket-lookup) just merged and rewrites the same bucket-lookup path this PR optimizes, so the rebase needs a real look at how the two interact (per-call allocation elimination vs. the new bucket lookup), not just a textual resolve.For the record, on its own base the head passed on macOS arm64 / rustc 1.98.1:
cargo test -p victory-formats --locked→ 23 passed / 0 failed.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:20:44Z.
Review: APPROVED
Tested
d45b04bon Windows 11, RTX 5070, MSVC:cargo test -p victory-formats23 passed, including the existingreference_chunks,bc7_mode6_blockandnoise_never_panics.cargo clippy -p victory-formats --all-targetsis clean.bcpack::decodebefore and after this PR. The two decoders agree on which inputs succeed and which fail (27,481 succeed, 32,519 fail), and every successful decode produces byte-identical output.dstorage(bcpack::decodeintointo_destination), turns the error into a failed request and does not read the buffer back, so I don't see a functional problem. It's worth one line in thedecodedocs saying thatdstis unspecified onErr.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:04:22Z.
Independent Windows check of
d45b04b0ab07daf732a2cd9dc85df9d5c9471de8(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).After a fresh build of the PR's
victory-formats, I ran the three new synthetic regressions withcargo test --locked -p victory-formats --lib -- workspace_reuse_matches_fresh_decode_across_all_formats rans_step_matches_reference_formula_for_all_models_and_slots bit_lookup_tables_match_reference_bit_ops --test-threads=1 --nocapture. All three passed. They check workspace reuse against fresh decodes, the rANS step against its reference formula, and the bit tables against direct bit operations. No throughput comparison or external reference chunks.Only source-built synthetic fixtures were used. AI-assisted verification.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:15Z.
Automated triage for the maintainers.
Needs work.
This rewrites most of
victory-formats/src/bcpack.rs(+764/−384) for speed. That is worth having, but the change needs evidence that the output stays the same:workspace_reuse_matches_fresh_decode_across_all_formatscompares the new code with itself (reused vs freshWorkspace), andreference_chunksstays ignored. Please add a differential test that checks the newdecodeagainstmain's decode, byte for byte, on synthetic streams for BC1/3/4/5/6/7. It should include every BC6H mode and BC7 control codes. Alternatively, report areference_chunksrun on both versions.main,decodedecodes every record before writing any block, so a short stream leavesdstuntouched. With streaming it writes blocks before the error. The only caller,dstorage.rs(bcpack::decodeinsideinto_destination), passes title memory, so a failed request now leaves partial data where the title expects none. Please keepmain's behaviour or explain why the change is fine.try_borrow_mutfallback inbcpack::decodeguards against re-entry, which cannot happen (decodedoes not call itself). Please drop it, along with the per-thread buffers kept for the thread's lifetime, unless measurements show a need.CI: no check runs are recorded for this head.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T08:52:04Z.
Review: APPROVED
Verified locally merged onto
main(940d32f, Windows 10 x64, Rust MSVC):cargo test -p victory-formats --lib— 40 passed, 0 failed, 5 ignored (benchmarks/external fixtures)cargo clippy -p victory-formats --all-targets -- -D warnings— 0 warningscargo xtask policy— ok (182 files ok)Synthetic tests only; no game data.
Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T18:47:33Z.
Review: COMMENTED
Measured the workspace trade-off requested in triage on
712f8909vs main63bcca43. Reusing the history helps small chunks. Most of the large-chunk heap saving survives even with a fresh workspace on every call.For 16,384 BC7 blocks, live decoder heap on main peaked at 541 KiB and returned to zero. A fresh PR workspace peaked at 29 KiB and returned to zero. On the PR's public thread-local path the first BC7 call added 29 KiB of history; the next call made zero allocations. One worker that had decoded all six formats retained 53.5 KiB in total (10 KiB shared by the plain formats, 14.5 KiB for BC6H, 29 KiB for BC7). These are allocator-requested bytes, excluding caller buffers and prebuilt tables.
On this workload an explicit worker-owned workspace delivered the small-chunk benefit too. Large-chunk speed was format-dependent: BC3 went from 5.44 to 5.70 ms on the thread-local path; a second process with the order reversed gave 5.44 to 5.68 ms. Windows x64, Ryzen 7 9800X3D, Rust 1.98.1 MSVC release, 12 timed batches after warm-up. Allocation counters were disabled for timings.
Valid-stream differential: 24 fixtures (BC1/3/4/5/6H/7 × 1/16/600/16,384 blocks) produced identical bytes on main and the PR, including all 14 BC6H modes, all 285 populated BC7 controls, fragment boundaries and history wrap. The 600-block fixtures also matched all six published golden hashes from the synthetic encoder and regression in #2735. This check covers successful decodes. The outstanding question about destination contents after an error remains open.
CPU only, synthetic inputs, no title run. Coordination. AI-assisted with Codex.
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.