SIGN IN SIGN UP

React Compiler: move compiled function bodies into AST instead of cloning (#37376)

tl;dr reduces memory churn by 7.8%, allocations by 4.1%, wall time by
~4%

## Summary

When compiled functions are written back to the AST,
`apply_compiled_functions` took a reference to a slice, and deep-cloned
each compiled body out of it. In theTS version this step assigns
references through Babel paths, which are essentially free. The Rust
port translated that as `.clone()` for safety, deep-copying the entire
codegen output for every compiled function.

Nothing needs these bodies after they are inserted, and the caller
already owns the vector. So this takes `compiled_fns` by value and moves
the data into the AST instead:

* `ReplaceFnVisitor` holds an `Option<CodegenFunction>` and moves it to
whatever arm matches
* Outlined function declarations move their id+params+body out of
`codegen_fn.outlined` rather than cloning them
* `needs_memo_import` is computed before the loop that consumes the
vector. Only the computation moved; the block that registers the import
stays where it was, so ordering and identifier numbering don't change.

This doesn't fully eliminate clones, just ones where it's easy to do a
move instead.

## How did you test this change?

All compiler fixtures pass with byte-identical output
A
Andrew Imm committed
d04798f2be8068f90813f917457a5b255ec6051d
Parent: 469c4ec
Committed by GitHub <noreply@github.com> on 9/2/2026, 5:11:26 AM