perf(shader): eliminate per-block allocations and SipHash in bitcode::opt #399

Manually merged
github merged 3 commits from github-bot/gh-399 into main 2026-12-05 17:30:49 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-04 00:18 UTC · original
tommiehansen:perf/bitcode-opt-alloc-hash → main · +586 −150 · 1 files · 3 commits · merged 2026-12-05 17:28 UTC

Standard benchmark — 2026-12-05

Reproducible CI result · head 6c77cd261757 · Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).

Workload Baseline (ms) Candidate (ms) Time change Verification
Translate corpus 5.299 3.994 −24.56% Identical
Guest load clusters 14.067 9.781 −30.42% Identical
Extended clusters 10.656 7.287 −31.59% Identical
Uniform SMEM/wide loads 8.603 6.266 −27.09% Identical
Node probe emission 1.785 1.492 −16.44% Identical

Baseline b581f7e; candidate as pinned above. All measured shader outputs identical; structurise timing inconclusive. CPU translation, not GPU frame rate.

Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.


What this does

eliminate per-block allocations and SipHash in bitcode::opt.

Checks

  • N/A: intended behavior-preserving compiler optimization, not new runtime behavior; sampled bitcode DXIL identical.
  • N/A: no new or changed switch.
  • No unrelated cleanup: Single bitcode/opt.rs optimization subject.
  • A test must exercise the change: expr_table_handles_collisions_lifo_removal_and_fast_clear and differential interpreter checks; 295 tests previously passed. Explicit before/after test and requested invariant/assertion follow-up pending.
  • Queue checked on 2026-12-04: #402/#404 optimize independent compiler stages; #468 also changes bitcode path.
  • Run cargo xtask policy on the final revision; no new game assets or build output intended.

Verified

Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.

Cost

CPU translation −21–29% in selected bitcode workloads; no GPU execution result.


Detailed implementation and historical validation

Summary

Eliminates per-instruction Key heap clones, SipHash lookups, and per-block trail/vector allocations inside victory_shader::emit::bitcode::opt::merge while producing byte-for-byte identical DXIL (equivalence = identical across all shaders/* workloads, no TRANSLATOR_VERSION change).

On Apple M5 (macOS), end-to-end shader translation throughput improves by 21.5%–29.1% across translation workloads (shaders/translate_corpus -24.50%, shaders/guest_load_clusters -27.91%, shaders/guest_load_clusters_extended -29.09%, shaders/uniform_smem_and_wide_loads -24.88%, shaders/uniform_guest_loads -21.50%, shaders/node_probe_emit -12.62%).

Changes (crates/victory-shader/src/emit/bitcode/opt.rs)

  • Zero-clone open-addressed expression table (ExprTable<TRACK_USED>): Replaces HashMap<Key, V> for both dominator-tree known and block-local read tables. Computes Fx hashes (key_hash) and value equality (key_eq, is_raw_srv) directly against self.insts[i].op without cloning Call/Gep/BufferRead operand Vec<V>s, uses precomputed func_flags (dx.op.getDimensions, dx.op.rawBufferLoad., dx.op.annotateHandle) instead of repeated string matching, performs LIFO backward-shift deletion on known, and resets only occupied slots via used indices on read::clear_fast().
  • Flat bit-fact array & empty-map fast paths (Facts): Replaces Facts::bits: HashMap<V, bool> with a reused Vec<u8> indexed by instruction id (bits_active fast path skips lookups when no branch facts are active, and !compares.is_empty() guards compare lookups).
  • Local Fx hasher (FxMap): Switches Facts::compares and joins from SipHash to BuildHasherDefault<Fx> (matching structure.rs, zero new dependencies).
  • Flat trail stacks & reusable MergeScratch: Replaces per-block Step::Leave(Vec<Key>, Learned) allocations with three flat LIFO trail Vecs (known_trail, bits_trail, cmp_trail), compacts Block::body in place instead of allocating Vec::with_capacity per block, hoists & reuses joins/join_key, and reuses all scratch buffers across optimise() fixed-point rounds.
  • Zero-overhead pure_loads empty check: Guards self.pure_loads.contains(&i) in Module::class() with !self.pure_loads.is_empty().
  • Unit test: Added expr_table_handles_collisions_lifo_removal_and_fast_clear covering hash collision chains, raw_srv/region namespace isolation, LIFO backward-shift deletion, and clear_fast() across capacity growth.

Benchmarks (CPU-Only Synthetic Suite, Apple M5 macOS)

Paired A/B/B/A (1152b9c vs 454f72e, --offline --cpu-only --profile standard --blocks 4 --suite shaders, 8 runs/side) via tools/benchmark-suite:

Benchmark 1152b9c (ms) 454f72e (ms) Change p-value 95% CI DXIL Equivalence
shaders/guest_load_clusters 6.894 4.968 -27.91% 0.0000 [-28.25%, -27.56%] identical
shaders/guest_load_clusters_extended 5.104 3.620 -29.09% 0.0000 [-29.83%, -28.34%] identical
shaders/uniform_smem_and_wide_loads 4.119 3.093 -24.88% 0.0000 [-25.01%, -24.75%] identical
shaders/translate_corpus 2.603 1.961 -24.50% 0.0001 [-26.46%, -22.49%] identical
shaders/uniform_guest_loads 1.438 1.126 -21.50% 0.0000 [-22.24%, -20.74%] identical
shaders/node_probe_emit 1.081 0.944 -12.62% 0.0000 [-13.07%, -12.16%] identical
shaders/structurise_guard_runs 9.566 9.409 -1.66% 0.0100 [-2.56%, -0.76%] (Inconclusive) identical
shaders/gpu_execute - - - - Unsupported in --cpu-only n/a

Verification & Reproducibility

  • Unit & randomized differential suite (victory-shader --lib):
    cargo test --offline -p victory-shader --lib
    
    295 passed; 0 failed; 2 ignored (including 400-seed differential interpreter check every_pass_leaves_what_random_programs_store across DEAD, FOLD, REUSE, FACTS, LOADS, ALL, plus expr_table_handles_collisions_lifo_removal_and_fast_clear).
  • Formatting & Windows cross-check:
    • rustfmt --edition 2024 --check crates/victory-shader/src/emit/bitcode/opt.rs clean.
    • cargo check --offline -p victory-shader --lib --tests --examples --target x86_64-pc-windows-msvc --features blake3/pure,host,diagnostics clean (guard_runs bench target has pre-existing pub(crate) ir::build error on main).
  • Benchmark Suite command:
    ./tools/benchmark-suite/run compare 1152b9c 454f72e --offline --cpu-only --profile standard --blocks 4 --suite shaders
    

Known Limitations

  • Benchmarks measure CPU-side shader translation and bitcode optimization on Apple M5 macOS; Windows D3D12 shader warm-up/compile-stall and gameplay frame-time impact require Windows hardware measurement.
  • Emitted DXIL is unchanged (identical), so steady-state GPU execution of cached shaders is unchanged; wins apply to uncached/warm-start shader translation.

Follow-up review fixes (2026-12-04)

Head: 526d8160499a1c6532b933dca6e6622653ee3b1e.

Add debug assertions for missing expression-trail removal entries and document why the region participates in hashing only for raw SRVs. Existing byte-identical DXIL evidence is for the bitcode optimization path on the reported synthetic corpus, not proof of all real shaders.

Pinned CI audit started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled.

Queue refresh — 2026-12-05

Merged upstream main b581f7e0a8086158953a64068ba29305d5450d68 into the existing branch without rewriting history. New head: 6c77cd26175778eb3e94b3b6ce36b0904c5fc959.

Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.

Standard CI raw-artifact follow-up (2026-12-05)

Synthetic CPU workload Base (ms) Candidate (ms) Paired time change
Extended guest-load translation 11.1202 7.4878 −33.25%
Guest-load translation 14.6662 10.0135 −32.47%
Corpus translation 5.5363 4.1369 −26.09%

All selected rows have identical output digests; corpus 95% CI −29.10% to −22.95%. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets rounds=8 (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. Pinned CI/artifacts.

**@⁠tommiehansen** on GitHub · 2026-12-04 00:18 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/399) `tommiehansen:perf/bitcode-opt-alloc-hash` → `main` · +586 −150 · 1 files · 3 commits · merged 2026-12-05 17:28 UTC ## Standard benchmark — 2026-12-05 [Reproducible CI result](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974594) · head `6c77cd261757` · Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm). | Workload | Baseline (ms) | Candidate (ms) | Time change | Verification | |---|---:|---:|---:|---| | Translate corpus | 5.299 | 3.994 | **−24.56%** | Identical | | Guest load clusters | 14.067 | 9.781 | **−30.42%** | Identical | | Extended clusters | 10.656 | 7.287 | **−31.59%** | Identical | | Uniform SMEM/wide loads | 8.603 | 6.266 | **−27.09%** | Identical | | Node probe emission | 1.785 | 1.492 | **−16.44%** | Identical | Baseline `b581f7e`; candidate as pinned above. All measured shader outputs identical; structurise timing inconclusive. CPU translation, not GPU frame rate. Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS. --- ## What this does eliminate per-block allocations and SipHash in bitcode::opt. ## Checks - N/A: intended behavior-preserving compiler optimization, not new runtime behavior; sampled bitcode DXIL identical. - N/A: no new or changed switch. - [x] No unrelated cleanup: Single `bitcode/opt.rs` optimization subject. - [ ] A test must exercise the change: `expr_table_handles_collisions_lifo_removal_and_fast_clear` and differential interpreter checks; 295 tests previously passed. Explicit before/after test and requested invariant/assertion follow-up pending. - [x] Queue checked on 2026-12-04: #402/#404 optimize independent compiler stages; #468 also changes bitcode path. - [ ] Run `cargo xtask policy` on the final revision; no new game assets or build output intended. ## Verified Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review. ## Cost CPU translation −21–29% in selected bitcode workloads; no GPU execution result. --- ## Detailed implementation and historical validation ## Summary Eliminates per-instruction `Key` heap clones, SipHash lookups, and per-block trail/vector allocations inside `victory_shader::emit::bitcode::opt::merge` while producing **byte-for-byte identical DXIL** (`equivalence = identical` across all `shaders/*` workloads, no `TRANSLATOR_VERSION` change). On Apple M5 (macOS), end-to-end shader translation throughput improves by **21.5%–29.1%** across translation workloads (`shaders/translate_corpus` **-24.50%**, `shaders/guest_load_clusters` **-27.91%**, `shaders/guest_load_clusters_extended` **-29.09%**, `shaders/uniform_smem_and_wide_loads` **-24.88%**, `shaders/uniform_guest_loads` **-21.50%**, `shaders/node_probe_emit` **-12.62%**). ### Changes (`crates/victory-shader/src/emit/bitcode/opt.rs`) - **Zero-clone open-addressed expression table (`ExprTable<TRACK_USED>`):** Replaces `HashMap<Key, V>` for both dominator-tree `known` and block-local `read` tables. Computes `Fx` hashes (`key_hash`) and value equality (`key_eq`, `is_raw_srv`) directly against `self.insts[i].op` without cloning `Call`/`Gep`/`BufferRead` operand `Vec<V>`s, uses precomputed `func_flags` (`dx.op.getDimensions`, `dx.op.rawBufferLoad.`, `dx.op.annotateHandle`) instead of repeated string matching, performs LIFO backward-shift deletion on `known`, and resets only occupied slots via `used` indices on `read::clear_fast()`. - **Flat bit-fact array & empty-map fast paths (`Facts`):** Replaces `Facts::bits: HashMap<V, bool>` with a reused `Vec<u8>` indexed by instruction id (`bits_active` fast path skips lookups when no branch facts are active, and `!compares.is_empty()` guards compare lookups). - **Local `Fx` hasher (`FxMap`):** Switches `Facts::compares` and `joins` from SipHash to `BuildHasherDefault<Fx>` (matching `structure.rs`, zero new dependencies). - **Flat trail stacks & reusable `MergeScratch`:** Replaces per-block `Step::Leave(Vec<Key>, Learned)` allocations with three flat LIFO trail `Vec`s (`known_trail`, `bits_trail`, `cmp_trail`), compacts `Block::body` in place instead of allocating `Vec::with_capacity` per block, hoists & reuses `joins`/`join_key`, and reuses all scratch buffers across `optimise()` fixed-point rounds. - **Zero-overhead `pure_loads` empty check:** Guards `self.pure_loads.contains(&i)` in `Module::class()` with `!self.pure_loads.is_empty()`. - **Unit test:** Added `expr_table_handles_collisions_lifo_removal_and_fast_clear` covering hash collision chains, `raw_srv`/region namespace isolation, LIFO backward-shift deletion, and `clear_fast()` across capacity growth. ## Benchmarks (CPU-Only Synthetic Suite, Apple M5 macOS) Paired A/B/B/A (`1152b9c` vs `454f72e`, `--offline --cpu-only --profile standard --blocks 4 --suite shaders`, 8 runs/side) via `tools/benchmark-suite`: | Benchmark | `1152b9c` (ms) | `454f72e` (ms) | Change | p-value | 95% CI | DXIL Equivalence | |---|---:|---:|---:|---:|---|---| | `shaders/guest_load_clusters` | 6.894 | 4.968 | **-27.91%** | 0.0000 | [-28.25%, -27.56%] | `identical` | | `shaders/guest_load_clusters_extended` | 5.104 | 3.620 | **-29.09%** | 0.0000 | [-29.83%, -28.34%] | `identical` | | `shaders/uniform_smem_and_wide_loads` | 4.119 | 3.093 | **-24.88%** | 0.0000 | [-25.01%, -24.75%] | `identical` | | `shaders/translate_corpus` | 2.603 | 1.961 | **-24.50%** | 0.0001 | [-26.46%, -22.49%] | `identical` | | `shaders/uniform_guest_loads` | 1.438 | 1.126 | **-21.50%** | 0.0000 | [-22.24%, -20.74%] | `identical` | | `shaders/node_probe_emit` | 1.081 | 0.944 | **-12.62%** | 0.0000 | [-13.07%, -12.16%] | `identical` | | `shaders/structurise_guard_runs` | 9.566 | 9.409 | -1.66% | 0.0100 | [-2.56%, -0.76%] (Inconclusive) | `identical` | | `shaders/gpu_execute` | - | - | - | - | Unsupported in `--cpu-only` | n/a | ## Verification & Reproducibility - **Unit & randomized differential suite (`victory-shader --lib`):** ```sh cargo test --offline -p victory-shader --lib ``` `295 passed; 0 failed; 2 ignored` (including 400-seed differential interpreter check `every_pass_leaves_what_random_programs_store` across `DEAD`, `FOLD`, `REUSE`, `FACTS`, `LOADS`, `ALL`, plus `expr_table_handles_collisions_lifo_removal_and_fast_clear`). - **Formatting & Windows cross-check:** - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/bitcode/opt.rs` clean. - `cargo check --offline -p victory-shader --lib --tests --examples --target x86_64-pc-windows-msvc --features blake3/pure,host,diagnostics` clean (`guard_runs` bench target has pre-existing `pub(crate)` `ir::build` error on `main`). - **Benchmark Suite command:** ```sh ./tools/benchmark-suite/run compare 1152b9c 454f72e --offline --cpu-only --profile standard --blocks 4 --suite shaders ``` ## Known Limitations - Benchmarks measure CPU-side shader translation and bitcode optimization on Apple M5 macOS; Windows D3D12 shader warm-up/compile-stall and gameplay frame-time impact require Windows hardware measurement. - Emitted DXIL is unchanged (`identical`), so steady-state GPU execution of cached shaders is unchanged; wins apply to uncached/warm-start shader translation. ### Follow-up review fixes (2026-12-04) Head: `526d8160499a1c6532b933dca6e6622653ee3b1e`. Add debug assertions for missing expression-trail removal entries and document why the region participates in hashing only for raw SRVs. Existing byte-identical DXIL evidence is for the bitcode optimization path on the reported synthetic corpus, not proof of all real shaders. Pinned [CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47438443784) started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled. ### Queue refresh — 2026-12-05 Merged upstream main `b581f7e0a8086158953a64068ba29305d5450d68` into the existing branch without rewriting history. New head: `6c77cd26175778eb3e94b3b6ce36b0904c5fc959`. [Fresh pinned CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636) is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim. ### Standard CI raw-artifact follow-up (2026-12-05) | Synthetic CPU workload | Base (ms) | Candidate (ms) | Paired time change | |---|---:|---:|---:| | Extended guest-load translation | 11.1202 | 7.4878 | −33.25% | | Guest-load translation | 14.6662 | 10.0135 | −32.47% | | Corpus translation | 5.5363 | 4.1369 | −26.09% | All selected rows have identical output digests; corpus 95% CI −29.10% to −22.95%. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets `rounds=8` (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. [Pinned CI/artifacts](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512649200/job/145651188720).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 00:18:41 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 03:00 UTC · original

Tested this natively on Windows 11 (MSVC), victory-shader only, against the merge base 1152b9c.

Tests

  • cargo test -p victory-shader --lib gives 420 passed, 1 failed, 4 ignored. Main gives 419 / 1 / 4 on the same box, so the extra pass is the new expr_table_handles_collisions_lifo_removal_and_fast_clear test. The single failure is size_tests::a_reused_descriptor_register_read_only_behind_its_flag, which fails the same way on main here (WARP), so it has nothing to do with this PR.
  • clippy on victory-shader with --all-targets shows the same warnings as main and nothing new from opt.rs (the guard_runs bench E0603 is already there on main).

Old vs new merge, call by call (local only, not pushed)
I copied main's merge (the Key / HashMap version with learn, key and raw_srv_key) into a test-only module and hooked optimise so every merge call ran the old version and the new one on the same input. For each call I compared the returned changed flag and a full dump of types, consts, insts and blocks.

  • Running the whole lib suite through the hook compared 8101 merge calls, all identical.
  • I extended the existing random program generator so it can also emit rawBufferLoad through annotated handles (two SRVs and one UAV), which gets the DOM_LOADS path some real traffic. 20000 seeds, with and without raw loads, over 9 pass sets (REUSE, LOADS, FACTS, FOLD|FACTS, DOM_LOADS, REUSE|LOADS|DOM_LOADS, MODULE, ALL, DEFAULT) came to about 755k merge calls with zero differences. Those runs hit about 48k dominated raw load reuses, 319k pure reuses and 99k block-local read reuses. The known table grew to 256 slots with up to 120 live entries, so growth and unwinding with a live trail did happen.
  • To check the harness could actually catch something, I dropped the region bump after a write in the new merge, and the diff caught it straight away. Swapping the backward-shift delete for a plain slot clear also failed, on the known.len == 0 debug assert at the end of the walk.

DXIL
Hashed every module the suite emits on both sides. 840 modules (716 distinct), and the sorted hash lists match exactly between main and this branch.

Reading the code

  • key_eq lines up with the old derived Key equality for every variant. Bin operands only commute for integer Add/Mul/And/Or/Xor, Cast still includes the result type, Call/Gep/Load compare operand ids, and raw SRV entries stay in their own namespace keyed by region. key_hash hashes the same normalized operands, so equal keys get equal hashes. Floats are still compared by constant id, so -0.0 and NaN behave exactly as before. Op::Gep and Op::Load carry no inbounds or alignment field, so the old key had nothing extra there either.
  • The table stays under half full, so probing always ends, and the backward-shift delete looks right to me (an entry only moves back when its home is not inside the gap). The trail stores hashes rather than slot indices, so a grow in the middle of a subtree is harmless.
  • Function flags keep exact names for getDimensions and annotateHandle and the prefix for rawBufferLoad., same as the old string checks.
  • One small thing worth a comment in the code. key_eq now reads the stored instruction's current op instead of a snapshot taken at insert time. That's fine today because the walk only rewrites the operands of the instruction it is on, but a future change that rewrites earlier instructions during the walk would quietly break lookups.

I didn't do any timing on Windows.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 03:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/399#issuecomment-7399584089) Tested this natively on Windows 11 (MSVC), victory-shader only, against the merge base 1152b9c. **Tests** - `cargo test -p victory-shader --lib` gives 420 passed, 1 failed, 4 ignored. Main gives 419 / 1 / 4 on the same box, so the extra pass is the new `expr_table_handles_collisions_lifo_removal_and_fast_clear` test. The single failure is `size_tests::a_reused_descriptor_register_read_only_behind_its_flag`, which fails the same way on main here (WARP), so it has nothing to do with this PR. - clippy on victory-shader with `--all-targets` shows the same warnings as main and nothing new from opt.rs (the `guard_runs` bench E0603 is already there on main). **Old vs new merge, call by call (local only, not pushed)** I copied main's `merge` (the `Key` / `HashMap` version with `learn`, `key` and `raw_srv_key`) into a test-only module and hooked `optimise` so every `merge` call ran the old version and the new one on the same input. For each call I compared the returned changed flag and a full dump of types, consts, insts and blocks. - Running the whole lib suite through the hook compared 8101 merge calls, all identical. - I extended the existing random program generator so it can also emit `rawBufferLoad` through annotated handles (two SRVs and one UAV), which gets the `DOM_LOADS` path some real traffic. 20000 seeds, with and without raw loads, over 9 pass sets (REUSE, LOADS, FACTS, FOLD|FACTS, DOM_LOADS, REUSE|LOADS|DOM_LOADS, MODULE, ALL, DEFAULT) came to about 755k merge calls with zero differences. Those runs hit about 48k dominated raw load reuses, 319k pure reuses and 99k block-local read reuses. The `known` table grew to 256 slots with up to 120 live entries, so growth and unwinding with a live trail did happen. - To check the harness could actually catch something, I dropped the region bump after a write in the new `merge`, and the diff caught it straight away. Swapping the backward-shift delete for a plain slot clear also failed, on the `known.len == 0` debug assert at the end of the walk. **DXIL** Hashed every module the suite emits on both sides. 840 modules (716 distinct), and the sorted hash lists match exactly between main and this branch. **Reading the code** - `key_eq` lines up with the old derived `Key` equality for every variant. Bin operands only commute for integer Add/Mul/And/Or/Xor, Cast still includes the result type, Call/Gep/Load compare operand ids, and raw SRV entries stay in their own namespace keyed by region. `key_hash` hashes the same normalized operands, so equal keys get equal hashes. Floats are still compared by constant id, so -0.0 and NaN behave exactly as before. `Op::Gep` and `Op::Load` carry no inbounds or alignment field, so the old key had nothing extra there either. - The table stays under half full, so probing always ends, and the backward-shift delete looks right to me (an entry only moves back when its home is not inside the gap). The trail stores hashes rather than slot indices, so a grow in the middle of a subtree is harmless. - Function flags keep exact names for `getDimensions` and `annotateHandle` and the prefix for `rawBufferLoad.`, same as the old string checks. - One small thing worth a comment in the code. `key_eq` now reads the stored instruction's current `op` instead of a snapshot taken at insert time. That's fine today because the walk only rewrites the operands of the instruction it is on, but a future change that rewrites earlier instructions during the walk would quietly break lookups. I didn't do any timing on Windows. AI-assisted: yes
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:20 UTC · original

This is the one to take from this batch: contained to one file, the equivalence argument holds, and 21–29% on the translator is a real number.

Three things I checked specifically, because they are what would silently corrupt dedup:

  • key_hash normalises commutative Bin operands exactly when key_eq accepts the swap (crates/victory-shader/src/emit/bitcode/opt.rs:1004-1032 vs :1065-1100), so equal keys cannot hash differently.
  • remove's asymmetric predicate (!raw_srv || s.region == region) (opt.rs:277-281) is safe only because key_hash mixes region in the raw_srv branch only. That is a real footgun for the next reader: if anyone folds region into the non-raw hash, every non-raw removal stops matching and the table leaks entries. Put that in a comment where the hash is built.
  • clear_fast (opt.rs:189-199) is only ever called on TRACK_USED=true tables and grow (opt.rs:201-224) rebuilds used, so no stale index survives a resize.

Two small asks:

  1. debug_assert on the miss path of remove (opt.rs:269-272) — today a removal that fails to find its entry returns silently and leaves len too high, which only surfaces much later as an unnecessary grow.
  2. In the PR body, say that the byte-identical DXIL comparison covers the bitcode path specifically. That claim is the only thing between this and a silent miscompile, so it should be unambiguous which harness proves it.

42 behind, and opt.rs has no commits on main since your merge base, so nothing was fixed underneath you.

**@⁠Luxuride** on GitHub · 2026-12-04 12:20 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/399#issuecomment-7411296200) This is the one to take from this batch: contained to one file, the equivalence argument holds, and 21–29% on the translator is a real number. Three things I checked specifically, because they are what would silently corrupt dedup: - `key_hash` normalises commutative `Bin` operands exactly when `key_eq` accepts the swap (`crates/victory-shader/src/emit/bitcode/opt.rs:1004-1032` vs `:1065-1100`), so equal keys cannot hash differently. - `remove`'s asymmetric predicate `(!raw_srv || s.region == region)` (`opt.rs:277-281`) is safe only because `key_hash` mixes `region` in the `raw_srv` branch *only*. That is a real footgun for the next reader: if anyone folds `region` into the non-raw hash, every non-raw removal stops matching and the table leaks entries. Put that in a comment where the hash is built. - `clear_fast` (`opt.rs:189-199`) is only ever called on `TRACK_USED=true` tables and `grow` (`opt.rs:201-224`) rebuilds `used`, so no stale index survives a resize. Two small asks: 1. `debug_assert` on the miss path of `remove` (`opt.rs:269-272`) — today a removal that fails to find its entry returns silently and leaves `len` too high, which only surfaces much later as an unnecessary `grow`. 2. In the PR body, say that the byte-identical DXIL comparison covers the *bitcode* path specifically. That claim is the only thing between this and a silent miscompile, so it should be unambiguous which harness proves it. 42 behind, and `opt.rs` has no commits on `main` since your merge base, so nothing was fixed underneath you.
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:19 UTC · original

Thanks @⁠Luxuride for the removal/hash review. 526d816 adds the missing-removal debug assertion and explains why region is hashed only for raw SRVs. The updated description scopes DXIL equivalence to the measured bitcode path. Current-head Standard CPU comparison reports 24.56% lower corpus translation time with identical output.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/399#issuecomment-7436365781) Thanks @⁠Luxuride for the removal/hash review. [526d816](https://github.com/tommiehansen/VIctory-xmem/commit/526d8160499a1c6532b933dca6e6622653ee3b1e) adds the missing-removal debug assertion and explains why region is hashed only for raw SRVs. The updated description scopes DXIL equivalence to the measured bitcode path. Current-head [Standard CPU comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974594) reports 24.56% lower corpus translation time with identical output.
github manually merged commit 0d512dcd36 into main 2026-12-05 17:30:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.