React Compiler 可以在编译期对组件进行优化,从而无需手动使用 useMemo、useCallback 和 memo。你可以在 ReactLynx 中使用 React Compiler 来对你的应用性能进行优化。
在 Rspeedy 中为 ReactLynx 开启 React Compiler 的步骤如下:
react-compiler-runtimelynx.config.js 配置中开启 React Compiler现在 ReactLynx 只支持 target 到 17。
react-hooks/react-compiler 以便及时发现无法优化的代码,请参考 React Compiler - ESLint 集成 进行配置。React Compiler 会自动分析你的组件并注入 memo 代码,从而减少对 useMemo、useCallback 或 React.memo 等手动优化的需求。这简化了你的代码库,并可在后续重新渲染期间显著提升性能,尤其是在更新频繁的界面中。
由于 React Compiler 会引入额外的运行时逻辑,因此可能会略微影响首帧直出的性能或初始后台线程渲染。我们建议在初始 IFR 性能要求不高,或者更注重重新渲染效率和开发者体验的情况下启用 React Compiler。
我们正在积极评估 React Compiler 在 ReactLynx 中的影响,并欢迎你进行实验和提供反馈,以帮助我们进行未来的改进。