为什么 React 的“只更新必要的”功能对性能很重要?
来自 https://facebook.github.io/react/docs/rendering-elements.html#react-only-updates-whats-necessary
React 仅重新渲染已更改组件的功能是否会影响浏览器渲染速度/性能?
React 声称只更新需要更新的 UI 组件,而不是整个页面,可以提高性能。来自 https://facebook.github.io/react/docs/optimizing-performance.html
Internally, React uses several clever techniques to minimize the number of costly DOM operations required to update the UI. For many applications, using React will lead to a fast user interface without doing much work to specifically optimize for performance.
在应用程序的更新/绘制循环中,不是必须重新绘制整个屏幕吗?如果浏览器必须在每一帧都重绘所有元素,那么它如何从仅渲染(重绘?)元素中的一个元素中受益?浏览器有一个帧率( MDN Frame Rate ),那么帧率如何与“只更新必要的内容”相协调?
我没有看到仅更新浏览器中的一个元素会如何影响浏览器的绘制。在实际推送渲染之前,React 的 javascript 对象表示可能很快,但如果 React 仅渲染与实际 DOM 的差异,这对性能有何帮助?
一个较低级别的问题可能是:当不重新绘制/重排布局时,浏览器如何节省计算?它不是必须绘制每一帧吗?
我已经提到了这些其他话题,但没有专门解决我的问题:
最佳答案
您自己在这里引用了答案:
Internally, React uses several clever techniques to minimize the number of costly DOM operations required to update the UI. For many applications, using React will lead to a fast user interface without doing much work to specifically optimize for performance.
React 并不关心优化低级问题,例如如何重绘页面(这可能由操作系统本身处理),而是如何有效地使用 DOM。众所周知,执行的 DOM 操作越多,整体性能就越差。 React 只是为了最小化那些 DOM 操作。
关于performance - React 是否只重新渲染改变了渲染速度的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44767312/