-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Themes: Avoid DOM reconciliation for existing themes on scroll #2915
Conversation
The theme component was using the pure render mixin to avoid reconciliation on re-render. Due to the complex nature of the props, the reconciliation was never being short-circuited. Implement a custom shouldComponentUpdate method that does a deep comparison on the theme object prop.
@@ -62,6 +61,10 @@ var Theme = React.createClass( { | |||
actionLabel: React.PropTypes.string | |||
}, | |||
|
|||
shouldComponentUpdate: function( nextProps ) { | |||
return ! isEqual( nextProps.theme, this.props.theme ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't comparing theme.id
and theme.active
be sufficient here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't comparing theme.id and theme.active be sufficient here?
Yeah you are right there, but the fact that there may not be a theme
obj supplied (in the placeholder usage case) pushed me to go for isEqual
as the simpler, more readable approach. Make sense, or should we just compare the relevant fields since this is on the speed-critical path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent headaches later, it's better to compare the whole theme object — it shouldn't be horrendously slow.
Code looks good. |
Themes: Avoid DOM reconciliation for existing themes on scroll
Before
After
These tables show time wasted reconciling component tree sections that have not changed. The start/stops have been placed around the
fetchNextPage()
call in the<themes-list-fetcher/>
, like this:This prints a table every time a scroll causes the next page of themes to be fetched and rendered. The tables above are towards the end of the entire set of themes.
The theme component was using the pure render mixin to avoid
reconciliation on re-render. Due to the complex nature of the
props, the reconciliation was never being short-circuited.
This PR Implements a custom shouldComponentUpdate method that does a deep
comparison on the theme object prop. We can see from the second table that no time is now wasted attempting to reconcile the huge amount of existing themes on the page.
To Test