perf(react_compiler): reduce allocations in reactive-places and mutation-aliasing passes#24476
Merged
Merged
Conversation
Merging this PR will improve performance by 4.03%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
Member
Author
Merge activity
|
…ion-aliasing passes (#24476) Two allocation-focused optimizations to the React Compiler's two hottest passes. Both are behavior-preserving — the full snapshot suite (`tests/snapshot.rs`, the ~1288 upstream fixtures) is unchanged, and no snapshots were regenerated. Profiling the compiler on real component files showed ~99% of compile time is the compiler core (parse/semantic/codegen are <1% combined), and the core is allocation-bound: compiling a 35 KB file did ~1.2M heap allocations. These two changes remove most of that. ### 1. Memoize post-dominator frontiers (`infer_reactive_places`) `is_reactive_controlled_block` recomputed each block's post-dominator frontier — a reverse-CFG walk that allocates several sets — on every call, which happens once per block and once per phi operand on every fixpoint iteration. The frontier depends only on the CFG, which is invariant across the fixpoint, so it is now computed once per block up front and looked up. ### 2. Inline `SmallVec` for `AbstractValue.reason` (`infer_mutation_aliasing_effects`) `AbstractValue.reason` was an `FxIndexSet<ValueReason>`, which heap-allocates on every clone. During inference these values are cloned constantly (once per entry on every `InferenceState` clone), so the reason sets dominated allocation in the pass. The sets are tiny — usually a single element, never more than one per `ValueReason` variant — so they are now backed by an inline, insertion-ordered `SmallVec`: clones no longer allocate, and `primary_reason` (first non-`Other` reason) keeps its ordering. ### Results Measured on real-world React component files (from `bluesky-social/social-app`), compile pass only, system allocator: | File | before | after | allocations | | --- | ---: | ---: | ---: | | Explore.tsx (35 KB) | 49.6 ms | 23.5 ms (**2.1×**) | 1.24M → 220K (**−82%**) | | MessageItem.tsx (30 KB) | 28.4 ms | 20.9 ms (**1.36×**) | 542K → 297K (**−45%**) | | Drawer.tsx (21 KB) | 9.7 ms | 8.7 ms (1.11×) | 183K → 155K (−15%) | \#2 is the larger lever — the reason-set clones dominated allocation in the pass. \#1 is a complementary ~6–10% CPU win from avoiding the redundant frontier recomputation. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
graphite-app
Bot
force-pushed
the
perf/react-compiler-hot-passes
branch
from
July 14, 2026 03:53
9462f0e to
1e3e626
Compare
graphite-app Bot
pushed a commit
that referenced
this pull request
Jul 14, 2026
…24480) Follow-up to #24476. Profiling the mutation-aliasing pass after that PR showed the `SmallVec<[ValueReason; 4]>` I introduced for `AbstractValue.reason` at **~7% of compile self-time** — it no longer allocates, but it's still copied on every `AbstractValue` clone, which happens once per entry on every `InferenceState` clone in the fixpoint. There are only 12 `ValueReason` variants, so the whole set fits in a `u16` bitmask. `ReasonSet` — and therefore `AbstractValue` — becomes `Copy`, so copying it is a register move instead of a memcpy, and membership / union / superset collapse to single bitwise ops. The one behavioral wrinkle is `primary_reason`, which returns the first non-`Other` reason: it now iterates in `ValueReason` declaration order rather than insertion order. The full snapshot suite (`tests/snapshot.rs`, the ~1288 upstream fixtures) is **unchanged**, confirming the ordering difference is not observable in output. ### Results Real-world React component files (from `bluesky-social/social-app`), compile pass only: | File | before | after | | --- | ---: | ---: | | Explore.tsx (35 KB) | 23.1 ms | **21.2 ms** (−8%) | | MessageItem.tsx (30 KB) | 21.3 ms | **20.5 ms** (−4%) | | Drawer.tsx (21 KB) | 8.6 ms | 8.7 ms (noise; few reasons) | Allocation count is unchanged — the `SmallVec` was already inline, so this is purely a copy/`memcpy` win. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Two allocation-focused optimizations to the React Compiler's two hottest passes. Both are behavior-preserving — the full snapshot suite (
tests/snapshot.rs, the ~1288 upstream fixtures) is unchanged, and no snapshots were regenerated.Profiling the compiler on real component files showed ~99% of compile time is the compiler core (parse/semantic/codegen are <1% combined), and the core is allocation-bound: compiling a 35 KB file did ~1.2M heap allocations. These two changes remove most of that.
1. Memoize post-dominator frontiers (
infer_reactive_places)is_reactive_controlled_blockrecomputed each block's post-dominator frontier — a reverse-CFG walk that allocates several sets — on every call, which happens once per block and once per phi operand on every fixpoint iteration. The frontier depends only on the CFG, which is invariant across the fixpoint, so it is now computed once per block up front and looked up.2. Inline
SmallVecforAbstractValue.reason(infer_mutation_aliasing_effects)AbstractValue.reasonwas anFxIndexSet<ValueReason>, which heap-allocates on every clone. During inference these values are cloned constantly (once per entry on everyInferenceStateclone), so the reason sets dominated allocation in the pass. The sets are tiny — usually a single element, never more than one perValueReasonvariant — so they are now backed by an inline, insertion-orderedSmallVec: clones no longer allocate, andprimary_reason(first non-Otherreason) keeps its ordering.Results
Measured on real-world React component files (from
bluesky-social/social-app), compile pass only, system allocator:#2 is the larger lever — the reason-set clones dominated allocation in the pass. #1 is a complementary ~6–10% CPU win from avoiding the redundant frontier recomputation.
🤖 Generated with Claude Code