-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wasted Rendering #1181
Comments
Why would a component declare a prop and then never use it? Why is optimization even needed for this? Sounds useless to me. |
Declare a prop here is for demonstrate only. |
Please kindly let me known why this optimization is unnecessary. |
@zeng450026937 fallthrough should cause the child to update, because it may get applied to the child root regardless of what the child's own render function uses. |
@yyx990803 Because fallthrough attrs is considered has no effect to child component, why not just use the previous vnode tree and patch it with new fallthrough attrs, but calling child render function to get a completely same vnode tree? |
If child component render a large list, which should be a noticeable impact. |
When you work on a framework you need to understand the trade-offs: premature optimizations often end up in gains that are simply too small to justify the extra complexity and edge cases they create. |
In fact, class/style falling through is the common scenario when writing a component. For example, if we are performing a tweening animation on child component, that would be unacceptable. In addition, define a component without explicit prop declarations, all attrs are considered as props, which result like a component declare a prop but never use it. When user who is simply passing through all props/attrs to child component, that also lead another component re-render again. If someone who is build a component library, unnecessary re-render is quietly a problem, and there’s no way to optimize this behavior currently. |
The basic assumption is that if a parent passes a dynamic prop to a child, then the child is expected to update when that prop changes. That's how parent-child updates work. Even a React PureComponent updates if any props change, no matter if it's used. If you want to do some expensive tweening with style bindings, you should wrap the child with a div and do the tweening on that div instead.
This is simply a correctness over maximum optimization trade-off - as I said, it's not worth it. If you want to fix it, be my guest, but I'm not going to waste time on that. |
Version
3.0.0-beta.12
Reproduction link
https://jsfiddle.net/450026937/whdtnqgk/32/
Steps to reproduce
What is expected?
Parent component update without calling child component's render function, as child component has it's own render effect.
What is actually happening?
Child component's render function is also invoked, but nothing changed with the node tree.
After looking into the source code, maybe we should split out the processing of parent update & self update in setupRenderEffect().
Making attrs shallow reactive like props will be a good idea, which allow just update child component's attrs & props(also fallthroughAttrs) during parent component update, and leaving child component trigger it's update if needed.
If this is not possible, an additional lifecycle hook, "shouldUpdateCompoent" should be needed to avoid wasted rendering.
The text was updated successfully, but these errors were encountered: