perf(codegen): FxHashMap cascade pt2 — value_sink/const_fold/fusion/register_estimate (+57.6%) - #239
Merged
0xClandestine merged 1 commit intoMay 30, 2026
Conversation
…d/fusion/register_estimate (+57.6%) Continues 0xClandestine#235 (licm) and 0xClandestine#236 (copy_prop/alg_simplify/unroll/vectorize) into the four remaining codegen passes that still used BTree containers keyed by `ValueId` (or `usize` position) for pure get/insert/contains: - **value_sink.rs** — `compute_global_use_count`'s use-count map (`BTreeMap<ValueId, usize>` → `FxHashMap`), `rebuild_with_sinking`'s `remove_at` set + `insert_before` map (`BTreeSet<usize>` / `BTreeMap<usize, …>` → Fx). Pre-sized from the outer plans/op counts. - **const_fold.rs** — DCE's `used` set + cross-block `cross_block_refs` set (`BTreeSet<ValueId>` → `FxHashSet`). `collect_uses` helper signature updated. - **fusion.rs** — `pinned_per_block` inner value (`BTreeSet<ValueId>` → `FxHashSet`); outer was already `FxHashMap`. `fuse_block` only does `.contains()` on the inner set, no iteration order needed. - **register_estimate.rs** — `block_max_live`'s `live` set (`BTreeSet<ValueId>` → `FxHashSet`), pre-sized to `block.ops.len()`. Microbench (M5 Max, release, 2000-op block, 10K iters side-by-side): BTreeSet (old): 40110.2 ns/call FxHashSet (new): 17000.2 ns/call → speedup : 2.36× (+57.6%) Pinned by `assert!(fx_ns_per * 1.05 <= bt_ns_per)`. `type_check.rs` intentionally NOT touched — overlaps with @0xClandestine's in-flight PR 0xClandestine#58 scope (introduces a new typed-value-environment model). Verified with 161/161 codegen tests passing, clippy clean, fmt clean.
TheTom
force-pushed
the
tom/perf/codegen-fxhash-cascade-pt2
branch
from
May 30, 2026 12:18
adfe4b0 to
f2707d7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues #235 (licm) and #236 (copy_prop/alg_simplify/unroll/vectorize) into the four remaining codegen passes that still used BTree containers keyed by `ValueId` (or `usize` position) for pure get/insert/contains:
`type_check.rs` intentionally NOT touched — overlaps with your in-flight PR #58 scope (introduces a new typed-value-environment model).
Measured (M5 Max, release, 2000-op block, 10K iters side-by-side)
`perf_block_max_live_btree_vs_fxhash` — BTreeSet impl kept inline in the test module:
```
=== block_max_live: 2000-op live-set walk × 10000 iters ===
BTreeSet (old): 40110.2 ns/call
FxHashSet (new): 17000.2 ns/call
→ speedup : 2.36× (+57.6%)
```
Pinned by `assert!(fx_ns_per * 1.05 <= bt_ns_per)`.
`cargo test -p metaltile-codegen --release perf_block_max_live_btree_vs_fxhash -- --ignored --nocapture`
Test plan