Shaders: eliminate heap allocations during CFG traversal #369
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!369
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-369"
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?
@pedrofort on GitHub · 2026-11-24 02:41 UTC · original
<head></head>pedrofort:optimize-shader-cfg→main· +197 −12 · 1 files · 1 commits · openMotivation
Exit::successors()allocates a temporary vector whenever a control-flow block's successors are queried, even though an exit has at most two successors.These allocations occur repeatedly during reverse postorder traversal, predecessor linking, irreducible control-flow analysis and register liveness analysis.
Implementation
Introduce allocation-free successor access and iteration.
Avoid cloning predecessor vectors during backward traversal.
Preserve successor order, duplicate successors and the existing public API.
No new dependencies or unsafe code.
Performance
Synthetic release microbenchmarks on Apple M5, macOS arm64, Rust 1.98.1, base commit
CFG blocks | Session 1 | Session 2 | Session 3 | Median speedup -- | -- | -- | -- | -- 770 | 4.536x | 4.814x | 4.683x | 4.683x 6,146 | 5.075x | 5.181x | 5.082x | 5.082x 24,578 | 4.438x | 4.482x | 4.972x | 4.482xd2a4bae.Each measurement performs 128 reverse postorder traversals. Each session includes warm-up and five measurements with alternating execution order.
Baseline control measurements comparing the original implementation against itself produced speedups between 0.987x and 1.009x.
These measurements apply specifically to CFG traversal, not end-to-end shader compilation or game performance.
Correctness
Successor ordering matches the original implementation.
Reverse postorder matches the original implementation across synthetic graphs containing branches, loops and unreachable blocks.
Full shader suite: 58 passed, 0 failed, 1 ignored.
Library Clippy with
-D warnings: clean.Asset policy: 151 files OK.
git diff --check: clean.Reproduction
cargo test --locked --release -p victory-shader --lib cfg_postorder_benchmark -- --ignored --nocaptureAll benchmark graphs are synthetic. No game assets were used.
AI-assisted implementation and test preparation (ChatGPT), with tests and benchmarks executed locally on Apple Silicon.
@jeremygold02 on GitHub · 2026-11-24 04:04 UTC · original
Thanks @pedrofort for this optimization. I tested head
341782191c557d278810a613d4dbf8cf47421094with:Result: 2 passed, 0 failed, 1 ignored (69 filtered out).
cfg_successors_preserve_orderandcfg_postorder_matches_referencepassed, covering successor order and reverse-postorder equivalence on the synthetic graphs. The ignored benchmark was not run, so this result does not measure the allocation or speedup claim.@Marvisak on GitHub · 2026-11-25 00:28 UTC · original
Automated triage for the maintainers.
Needs work (small).
Exit::successor_atandsuccessor_iter(crates/victory-shader/src/ir.rs) keep the order ofExit::successors(), including aBranchwhose two targets are the same block, and the call-site changes (reverse_postorder,link,irreducible_edge,split_irreducible,multi_entry_loop,liveness) keep the old behaviour. To merge: runcargo fmt(doubled blank line inmod tests); drop the ~70-line ignoredcfg_postorder_benchmarkand keepcfg_successors_preserve_orderandcfg_postorder_matches_reference; and show the end-to-end effect (e.g.victory translatewall time before/after), since a 4.5x speed-up on reverse postorder alone doesn't say what it saves per shader.CI: no check runs on the head commit.
Generated by Claude Code
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.