Formats: BCPack block histories without per-call allocation or zeroing #2032
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2034"
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 StExpeditus on 2026-11-25T03:49:19Z.
Part of #703.
The per-call
vec![Default::default(); HISTORY]inplain/bc6/bc7cost one heap allocation plus a 10-30 KiB memset on everydecodecall. Ring entries are always written before they are read (block i writes sloti % HISTORY; a referencerof block i reads the slot blocki - rwrote, andr <= 255 < HISTORY), so the slots never need initialising.[MaybeUninit::uninit(); HISTORY]skips both the allocation and the zeroing; the oneunsafe(inpick) carries the invariant as its SAFETY comment.Measured with
bcpack_throughput's synthetic streams (cargo test --release -p victory-formats bcpack_throughput -- --ignored --nocapture, extended locally to small block counts):Small decodes are the mip-tail case that texture streaming does most, where the zeroing was proportionally heaviest.
cargo test -p victory-formats: 38 passed, 0 failed.The other per-call allocation (
recordsindecode, proportional to block count) and a fused streaming decode are left to follow-ups.Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:55:14Z.
Triage verdict — Keep the narrow history change, preserve a wraparound regression (
de45bec)Evidence
Checks and limits
Next step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:06:56Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-formats --lib bcpack::— 9 passed, 0 failed (2 ignored)cargo clippy -p victory-formats --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean optimization avoiding per-call allocation and zeroing of BCPack block histories. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:02Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-formats --locked.38 passed / 0 failed. BCPack block histories without per-call allocation or zeroing — allocation-free history tracking; 38 passed / 0 failed / 5 ignored (current formats baseline).
Imported from Marvisak/VIctory. Originally posted by StExpeditus on 2026-11-25T09:05:11Z.
Addressed the triage note: added
references_survive_the_dictionary_transition_and_the_history_wrap.assert_eq.cargo test -p victory-formats: 39 passed, 0 failed.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:51Z.
Automated triage for the maintainers.
Merge candidate. In
crates/victory-formats/src/bcpack.rs, the per-callvec[..; HISTORY]history rings inplain,bc6andbc7become stack arrays ofMaybeUninit, andpickreads them with oneunsafeassume_init_ref. Recommending a look, not approving.What I checked:
referencesreturnsusize::from(u8), sor <= 255 < HISTORY(256). Slot(i - r) % HISTORYwas written by blocki - rand not overwritten since. Each block writes its slot only after bothpickcalls.Copy, so the array repeat is valid.references_survive_the_dictionary_transition_and_the_history_wrapcovers the dictionary-to-history transition and the ring wrap for BC4, BC6 and BC7.Notes for the maintainer:
unsafefor a micro-optimization. A safe stack array ([T::default(); HISTORY]) would also remove the allocation but keep the memset, if you prefer nounsafehere.CI: not run on this head (no check runs reported).
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:51:49Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 — memory-safety invariants are airtight and ready to merge:[MaybeUninit<...>; 256]:references()computes indices viau8::wrapping_add(0..=255);HISTORY = 256andDICTIONARY = 255. Inpick(),r == 0yields zero,r > iindexesdictionary[r - i - 1](<= 254), and1 <= r <= iimplies(i - r) % 256 != i % 256with no intervening overwrite, sohistory[(i - r) % HISTORY].assume_init_ref()is guaranteed initialized.Plain,(Bc7Ep, Bc7Ix),(Bc6Ep, Bc6Ix)) areCopywith noDrop, so early error returns inbc6/bc7(bcpack.rs:781, 1093) cannot drop uninitialized slots; stack-local arrays are naturally thread-safe.Local verification:
cargo test --locked -p victory-formats: 47/47 passed (including newreferences_survive_the_dictionary_transition_and_the_history_wrapacross 600 blocks for BC4/BC6/BC7)cargo clippy+cargo xtask policy(191 files ok): 0 warningsView 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.