perf(victory-formats): reuse capped thread-local decode scratch and history buffers in bcpack #408

Closed
github-bot wants to merge 1 commit from github-bot/gh-408 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:50 UTC · original
Lewandox:perf/bcpack-reuse-decode-buffers → main · +125 −32 · 1 files · 1 commits · closed without merging

Summary

Eliminates repeated per-decode heap allocations and zero-fills in victory_formats::bcpack::decode (third_party/victory/crates/victory-formats/src/bcpack.rs):

  1. Reuse capped thread-local lane-record scratch buffer:
    • decode() previously allocated and zeroed vec![0u8; blocks * stride] on every BCPack texture decode (up to multi-MiB per decode on DirectStorage worker threads).
    • Now reuses a thread-local RECORDS_SCRATCH buffer (capped at RECORDS_CAP = 4 MiB on exit so oversized decodes immediately return RAM to the OS).
  2. Reuse thread-local history ring buffers (plain, bc6, bc7):
    • plain(), bc6(), and bc7() previously allocated a fresh vec![...; HISTORY] on every decode call. Since pick(i, r, history, ...) only reads history[(i - r) % HISTORY] for r <= i, reusing the fixed-size per-thread history buffers produces bit-identical output with zero per-call heap allocations.
  3. Unit test:
    • Verifies with_records_scratch reuses allocations up to RECORDS_CAP, drops oversized buffers on exit, and preserves identical output across consecutive decodes.

Verification

  • cargo test -p victory-formats --lib bcpack
  • cargo xtask policy inside third_party/victory
**@⁠Lewandox** on GitHub · 2026-11-26 17:50 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/408) `Lewandox:perf/bcpack-reuse-decode-buffers` → `main` · +125 −32 · 1 files · 1 commits · closed without merging ## Summary Eliminates repeated per-decode heap allocations and zero-fills in `victory_formats::bcpack::decode` (`third_party/victory/crates/victory-formats/src/bcpack.rs`): 1. **Reuse capped thread-local lane-record scratch buffer**: - `decode()` previously allocated and zeroed `vec![0u8; blocks * stride]` on every BCPack texture decode (up to multi-MiB per decode on DirectStorage worker threads). - Now reuses a thread-local `RECORDS_SCRATCH` buffer (capped at `RECORDS_CAP = 4 MiB` on exit so oversized decodes immediately return RAM to the OS). 2. **Reuse thread-local history ring buffers (`plain`, `bc6`, `bc7`)**: - `plain()`, `bc6()`, and `bc7()` previously allocated a fresh `vec![...; HISTORY]` on every decode call. Since `pick(i, r, history, ...)` only reads `history[(i - r) % HISTORY]` for `r <= i`, reusing the fixed-size per-thread history buffers produces bit-identical output with zero per-call heap allocations. 3. **Unit test**: - Verifies `with_records_scratch` reuses allocations up to `RECORDS_CAP`, drops oversized buffers on exit, and preserves identical output across consecutive decodes. ## Verification - `cargo test -p victory-formats --lib bcpack` - `cargo xtask policy` inside `third_party/victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:52:26 +00:00
github-bot closed this pull request 2026-11-27 00:36:09 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:09 UTC · original

Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

The change came without a measurement (rule 2 of AGENTS.md asks for one for performance work).

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

**@⁠LooperSalty** on GitHub · 2026-11-26 23:09 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/408#issuecomment-7205298579) Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). The change came without a measurement (rule 2 of AGENTS.md asks for one for performance work). Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.