Skip to content

perf(codegen): FxHashMap cascade pt2 — value_sink/const_fold/fusion/register_estimate (+57.6%) - #239

Merged
0xClandestine merged 1 commit into
0xClandestine:devfrom
TheTom:tom/perf/codegen-fxhash-cascade-pt2
May 30, 2026
Merged

perf(codegen): FxHashMap cascade pt2 — value_sink/const_fold/fusion/register_estimate (+57.6%)#239
0xClandestine merged 1 commit into
0xClandestine:devfrom
TheTom:tom/perf/codegen-fxhash-cascade-pt2

Conversation

@TheTom

@TheTom TheTom commented May 30, 2026

Copy link
Copy Markdown
Collaborator

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:

File Change
`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/BTreeMap of `usize` → Fx). All pre-sized from outer plans/op counts.
`const_fold.rs` DCE's `used` set + cross-block `cross_block_refs` (`BTreeSet` → `FxHashSet`). `collect_uses` helper signature updated.
`fusion.rs` `pinned_per_block` inner value (`BTreeSet` → `FxHashSet`); outer was already `FxHashMap`. `fuse_block` only does `.contains()` on the inner set — no iteration order.
`register_estimate.rs` `block_max_live`'s `live` set (`BTreeSet` → `FxHashSet`), pre-sized to `block.ops.len()`.

`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

  • `cargo test -p metaltile-codegen --lib` — 161/161 pass
  • `cargo clippy --workspace --all-targets --all-features -- -D warnings` — clean
  • `cargo fmt --all --check` — clean
  • `cargo test -p metaltile-codegen --release perf_block_max_live_btree_vs_fxhash -- --ignored --nocapture` — +57.6%

@github-actions github-actions Bot added the performance Performance improvement label May 30, 2026
…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
TheTom force-pushed the tom/perf/codegen-fxhash-cascade-pt2 branch from adfe4b0 to f2707d7 Compare May 30, 2026 12:18
@0xClandestine
0xClandestine merged commit 71ce072 into 0xClandestine:dev May 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants