What's the overhead of Composite Components? #12
-
From the Render, Commit, and Mount post.
...
This might be a React Core question, not a RN Core one. Does the above mean there is no overhead of having many Composite Components like ContextProviders? Or, is there any overhead for having many Composite Components? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If I understand the question correctly, the answer is that there's no overhead. Native ShadowNode is created only in places native components are required (e.g. if some function returns |
Beta Was this translation helpful? Give feedback.
-
Hey @AndreiCalazans, interesting question! I'll share my understanding of composite components. Context API is special. It is not a composite component. Context does has performance implications. Specifically for updates as it becomes more laborious to identify changes in the fiber tree. Component is no longer just a function of state and props, but context is added to the mix. Someone with React knowledge is better suited to answer this in depth but I thought I would share my understanding. Composite component only really adds extra function call. As React executes render function, it will see return value of the render function is another function that it needs to execute. I would say the overhead is whatever the cost of a function call is in JavaScript and it negligible for most purposes. If you do end up running any benchmarks, I would like to take a look! Thank you. |
Beta Was this translation helpful? Give feedback.
Hey @AndreiCalazans,
interesting question! I'll share my understanding of composite components.
Context API is special. It is not a composite component. Context does has performance implications. Specifically for updates as it becomes more laborious to identify changes in the fiber tree. Component is no longer just a function of state and props, but context is added to the mix. Someone with React knowledge is better suited to answer this in depth but I thought I would share my understanding.
Composite component only really adds extra function call. As React executes render function, it will see return value of the render function is another function that it needs to execute. I would say t…