Bitcode clean-up: FxHash tables and join keys allocated once #269

Open
github-bot wants to merge 2 commits from github-bot/gh-269 into main AGit
Owner

@⁠amine23012004 on GitHub · 2026-11-26 13:56 UTC · original
amine23012004:perf/bitcode-opt-fx-hash → main · +87 −79 · 5 files · 2 commits · open

Bitcode clean-up: FxHash tables and join keys allocated once

What. The bitcode optimiser's tables (known, read, Facts, joins) used the standard library's SipHash. Profiling a translation showed hashing their small integer keys as the largest single cost of emit. They now use the FxHash that structure.rs already had; it moves to a small crate::fx module so both share it (no new dependency). Each join's key is also built at its final size and sorted with sort_unstable (its elements are totally ordered, so the result is the same) instead of collected, sorted and then grown by one.

Same output. DXIL is byte-for-byte identical before/after on the programs below, compared against two separate runs of main. SipHash is seeded per process, so the output could not depend on the tables' iteration order before this either.

Measured (Linux, release, best of 25, emit only; synthetic pixel programs: blocks of 8 VALU ops under v_cmpx/s_cbranch_execz with EXEC saved and restored, ending in exp mrtz):

instructions main this PR
1,205 12.5-13.5 ms 8.3 ms (7.3 ms with the second commit)
4,805 51-57 ms 33 ms (29.4 ms with the second commit)

Second commit: lower too. lower's tables keyed by ir::Value (values, floats, lane bits, phi sites, uniform values...) were the next SipHash cost once the optimiser's were gone; they now use crate::fx as well (a Set alias is added). The per-block sections that wave::sections returns keep their std type. Same DXIL byte for byte; emit on 4,805 instructions goes from 33 ms to 29.4 ms on top of the first commit.

These are synthetic programs, not the title's shaders: I have not measured victory shaders on a real dump, so the real-world gain is unconfirmed.

Checks. cargo test -p victory-shader (209 passed), cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings clean.

Independent of #268 (the ir::build change); the two touch different files.

🤖 Generated with Claude Code

**@⁠amine23012004** on GitHub · 2026-11-26 13:56 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/269) `amine23012004:perf/bitcode-opt-fx-hash` → `main` · +87 −79 · 5 files · 2 commits · open ## Bitcode clean-up: FxHash tables and join keys allocated once **What.** The bitcode optimiser's tables (`known`, `read`, `Facts`, `joins`) used the standard library's SipHash. Profiling a translation showed hashing their small integer keys as the largest single cost of `emit`. They now use the FxHash that `structure.rs` already had; it moves to a small `crate::fx` module so both share it (no new dependency). Each join's key is also built at its final size and sorted with `sort_unstable` (its elements are totally ordered, so the result is the same) instead of collected, sorted and then grown by one. **Same output.** DXIL is byte-for-byte identical before/after on the programs below, compared against two separate runs of `main`. SipHash is seeded per process, so the output could not depend on the tables' iteration order before this either. **Measured** (Linux, release, best of 25, `emit` only; synthetic pixel programs: blocks of 8 VALU ops under `v_cmpx`/`s_cbranch_execz` with EXEC saved and restored, ending in `exp mrtz`): | instructions | main | this PR | |---:|---:|---:| | 1,205 | 12.5-13.5 ms | 8.3 ms (7.3 ms with the second commit) | | 4,805 | 51-57 ms | 33 ms (29.4 ms with the second commit) | **Second commit: `lower` too.** `lower`'s tables keyed by `ir::Value` (values, floats, lane bits, phi sites, uniform values...) were the next SipHash cost once the optimiser's were gone; they now use `crate::fx` as well (a `Set` alias is added). The per-block sections that `wave::sections` returns keep their std type. Same DXIL byte for byte; `emit` on 4,805 instructions goes from 33 ms to 29.4 ms on top of the first commit. These are synthetic programs, not the title's shaders: I have not measured `victory shaders` on a real dump, so the real-world gain is unconfirmed. **Checks.** `cargo test -p victory-shader` (209 passed), `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings` clean. Independent of #268 (the `ir::build` change); the two touch different files. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The optimiser's tables (known values, reads, facts, joins) used the
standard library's SipHash; profiled on a synthetic 4,805-instruction pixel
program, hashing their small integer keys was the largest single cost of
`emit`. They now use the FxHash that `structure` already had, moved to
`crate::fx` so both share it. Each join's key is also built at its final
size and sorted unstable (its elements are totally ordered, so the order is
the same) instead of collected, sorted and grown by one.

Same DXIL byte for byte on the synthetic programs (SipHash is seeded per
process, so the output could not depend on the tables' order before
either). `emit` on 4,805 instructions: 51-57 ms -> 33 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:00:51 +00:00
`lower`'s tables (values, floats, lane bits, phi sites, uniform values...)
are keyed by `ir::Value` and still used SipHash, the next largest hashing
cost once the bitcode optimiser's went. They now use `crate::fx` (`Set`
added for the sets). The per-block sections that `wave::sections` returns
keep their std type.

Same DXIL byte for byte on the synthetic programs; `emit` on 4,805
instructions: 33 ms -> 29.4 ms (on top of the previous commit).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/269/head:github-bot/gh-269'
git switch 'github-bot/gh-269'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-269'
git switch 'github-bot/gh-269'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-269'
git switch 'github-bot/gh-269'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-269'
git switch 'main'
git merge --squash 'github-bot/gh-269'
git switch 'main'
git merge --ff-only 'github-bot/gh-269'
git switch 'main'
git merge 'github-bot/gh-269'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.