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

Open
amine23012004 wants to merge 2 commits from upstream-pr/269 into main
amine23012004 commented 2026-11-26 13:56:48 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by amine23012004 on 2026-11-26T13:56:48Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6628197880 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/269). Originally posted by [amine23012004](https://github.com/amine23012004) on 2026-11-26T13:56:48Z. --- ## 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)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/269:upstream-pr/269'
git switch 'upstream-pr/269'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/269'
git switch 'upstream-pr/269'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/269'
git switch 'upstream-pr/269'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/269'
git switch 'main'
git merge --squash 'upstream-pr/269'
git switch 'main'
git merge --ff-only 'upstream-pr/269'
git switch 'main'
git merge 'upstream-pr/269'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
avatarmanz/VIctory-7900XTX!269
No description provided.