Repository navigation
Conversation
`Lower::live_edges` skips a phi reached with a set of conditions when an earlier set of that phi is a subset of it. It found one by scanning every earlier set, and in programs with much control flow a phi is reached with tens of thousands of sets, so the scan made the walk quadratic: some programs took tens of seconds to lower, nearly all of it here. A set holds at most four conditions, so it has at most 16 subsets. Once a phi has 16 earlier sets, they are also kept in an index, as sets (sorted, without repeats), and each subset of the new set is looked up there instead. Below that the scan stays: it is cheaper than the lookups. The walk takes the same decisions, so the live edges are the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotekompotek
left a comment
There was a problem hiding this comment.
Sound optimization: 'some earlier set is a subset' is exactly enumerable via the new set's subsets (2^len each) — once |done| exceeds 1<<MAX_KNOWN that's bounded work instead of a linear scan over tens of thousands of entries. The sorted-set canonicalization in set() makes HashSet indexing well-defined, and the <=MAX_KNOWN bound means the subset enumeration can't blow up. LGTM.
|
Reviewed and verified
|
|
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.
AI-assisted (Hy4 flash). |
…ests `Known` and the sets of it each phi was reached with (`Reached`, the scan and the index) move from `Lower::live_edges` into `emit/lower/known.rs`, so the index path can be tested on its own: a test adds 4,000 paths of two to four of twelve conditions and checks each answer against a scan of every earlier set (well past the 16 sets where the index takes over), and one checks a set's sorting and subsets. `lower.rs` gets about 1 KB smaller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks both. Following @fuzeofficlal's two notes,
Checked again: the whole pack's 25,889 containers translate to the same output as AI-assisted (Claude Code, Claude Opus 5.5). |
|
Re-checked the new head Delta review ( New tests. Both pass. They are unit tests of the new Results on
AI-assisted (Claude Code). |
|
Automated triage for the maintainers. Merge candidate. This replaces the linear subset scan in CI: passing. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified against origin/main (63bcca4):
cargo test -p victory-shader --lib known:: -- --test-threads=1: passed.cargo test -p victory-shader --lib structure:: -- --test-threads=1: 13/13 passed (1 ignored bench).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.
Cleanly indexes earlier condition sets for live phi edge lookups.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed 20d18785 (git merge-tree against main 63bcca43 is clean):
- The indexed subset lookup in
crates/victory-shader/src/emit/lower/known.rspreserves the exact original subset test: sorting and deduplicating stored predicates leaves membership unchanged, the empty set is handled cleanly both below and above the 16-entry index threshold, andemit/lower.rstraversal still preserves the ordered 4-condition history. - Merging onto
63bcca43shrinkscrates/victory-shader/src/emit/lower.rsfrom 520,563 bytes to 519,410 bytes (4,878 bytes below the 524,288-byte policy limit).
Verified locally on Windows 11 with RTX 5090 and WARP (VICTORY_WARP=1):
xtask policy(191 files ok) andcargo clippy -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.known::tests2/2,structure::tests13/13 (1 ignored),emit::lower::tests33/33, andwaterfall_tests5/5 (both RTX 5090 and WARP) all pass, plus an independent exhaustive differential model check over 2,418,025 ordered predicate pairs (length 0..=4).
From a tester working with Claude (AI-assisted: Claude Code, Claude Opus 5.5 found the hot spot, wrote the change and ran the measurements; I directed and checked it).
The problem
Some programs take tens of seconds to translate, nearly all of it in
Lower::live_edges. On13f91caone program took 527 s insidetranslate --cacheunder Proton (the warm-up sat at 26,502 of 26,503 containers for minutes and looked hung); #2062 made each step cheaper, but the shape is still quadratic.live_edgesskips a phi reached with a set of conditions when an earlier set of that phi is a subset of it. It finds one by scanning every earlier set of the phi, and in programs with a lot of control flow a phi is reached with very many sets (up to about 24,000 on one phi in the three slow programs below), so the scan grows with the square of them. A profile of one such program (Linuxperf, release build with debug info) put 92% of its translation time in that scan (fill_phis→live_edges→slice::contains).The change
One function,
live_edgesinemit/lower.rs:MAX_KNOWN(4) conditions, so it has at most 16 subsets. Once a phi has 16 earlier sets, they are also kept in an index as sets (sorted, without repeats), and each subset of the new set is looked up there instead of scanning.Knowngetsset()(sorted, without repeats) andsubsets();nonebecomes theNONEconstant they share.The walk takes the same decisions (an earlier set is a subset of the new one exactly when one of its subsets is in the index), so the live edges are the same.
Measurements
All on the title's shader pack (1.0.2.1, my own copy), 25,889 distinct containers, each through
emit::translate_withfrom a small harness outside the tree (native Linux, release build),mainf3578e3against this branch. No game data here, only counts, times and hashes.Output: for every one of the 25,889 containers the result is identical (BLAKE3 of the
Debugform of theHostShader, or the same error): 0 differences.Work (user-mode instructions retired,
perf stat, 8 threads, three alternating rounds, the harness's own parsing subtracted; instructions rather than time because the machine was shared):mainmainSo the slow programs do 2-4x less work, and typical programs about 0.6% more (the sets are sorted when stored). On
mainthe cost of the slow ones varies a lot between runs: the walk's order follows hash-map iteration order.Time, one thread, single programs (two runs each,
main→ branch):maincbe258e224519eac6f06d377496b2eb7134379ec4e54d218Testing
cargo test -p victory-shader --lib --release -- --test-threads=1, cross-built for Windows and run under GE-Proton 11-14 (vkd3d-proton) on an RX 9070 XT with RADV (Mesa 26.3.1),dxil.dllfrom DXC v1.9.2609: 300 passed, 2 failed, the same 2 as onmainwith the same setup (hosts_that_do_not_fuse_are_namedandstub_pipeline_is_created: under vkd3d-proton the "WARP" adapter is the real GPU and the DXIL digest is not checked).cargo test --release -p victory-shader(with Shader tests: the descriptor-join tests build off Windows #2766 so the tests build off Windows): 172 passed, 0 failed.cargo clippy -p victory-shader --locked -- -D warnings: clean.rustfmt: no change in the edited lines.🤖 Generated with Claude Code