perf: Enable React Compiler for improved runtime performance 🚀#3690
perf: Enable React Compiler for improved runtime performance 🚀#3690sanjaiyan-dev wants to merge 2 commits intopmndrs:masterfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d789930:
|
travisbreaks
left a comment
There was a problem hiding this comment.
A few concerns before this ships:
-
No R3F-specific benchmarks. The cited Meta numbers are from standard React DOM apps. R3F's hot path is
useFramerunning at 60fps with imperative ref mutations, which is architecturally different from anything Meta benchmarked. Can you share before/after measurements on a non-trivial R3F scene (e.g., the drei storybook or an examples page)? -
Compiler + imperative mutation compatibility. R3F's core patterns rely heavily on mutating Three.js objects via refs inside
useFrame, and the reconciler itself does imperative property application outside standard React render flow. The compiler's auto-memoization assumes pure rendering and standard React semantics. Without explicit"use no memo"directives on critical paths (the reconciler,useFrameinternals,useThree), there's a real risk of silent miscompilation where closures get incorrectly cached or JSX elements get over-memoized. -
No compiler configuration. This applies
babel-plugin-react-compilerwith zero config to the entire library. At minimum, I'd expect to seecompilationModeand targeted opt-outs for the reconciler and frame loop internals. Shipping this as the default for all R3F users without an escape hatch is a significant surface area change for a minor bump.
|
react-three-fiber isn't a component library that can take advantage of compiler memoization—we ship the React runtime it implements over. So, the common advice for libraries is moot here. I would accept improvements to documentation or examples to leverage the compiler, or a similar change to component libraries over react-three-fiber, such as Drei. |
Hi, Thank you for your feedback and suggestions! Sorry for the delay in my response. To address your points:
|
Ah, got it! I'll open a PR in |
Description:
This PR integrates the React Compiler to align the framework with modern React standards and improve overall performance.
Key Benefits: