Big O / Time Complexity for React Lifecyle

时间:2018-02-26 17:51:16

标签: javascript reactjs big-o

What's the time complexity for the React component lifecycle?

I was reading a post here recently that suggested where a closure was called for, it could be a good idea to use a component instead. In term of vanilla JavaScript, time complexity should be the same or similar since in the end both are functions. Space complexity may be larger for the component. But the component has to go through the React lifecycle, correct? Which I assume adds overhead.

1 个答案:

答案 0 :(得分:0)

我的直觉说复杂性是[1,2,3]+[4,5] reconciliation docs的快速峰值似乎支持了我的直觉。

每个操作,生命周期与否,在树中每个节点最多只发生一次,因此O(n)的上限然而在实践中它可能会少一些,因为组件不总是渲染{感谢{{1} 1}}和其他子树渲染技术。