Skip to content
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

Reduce wasted renders for column_loading.js #5021

Merged
merged 2 commits into from
Sep 20, 2017

Conversation

nolanlawson
Copy link
Contributor

This reduces some wasted time for this component, as shown in this ReactPerf.printWasted() before and after:

out2

(Scenario: load the local timeline in mobile view.)

@@ -3,17 +3,25 @@ import PropTypes from 'prop-types';

import Column from '../../../components/column';
import ColumnHeader from '../../../components/column_header';
import ImmutablePureComponent from 'react-immutable-pure-component';
Copy link
Contributor Author

@nolanlawson nolanlawson Sep 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried React.PureComponent but for some reason that resulted in more wasted renders than ImmutablePureComponent.

render() {
let { title, icon } = this.props;
title = title || '';
icon = icon || '';
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { title = '', icon = '' } = this.props;

Is it not acceptable in the above writing style?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah...

static propTypes = {
  title: PropTypes.oneOfType(PropTypes.node, PropTypes.string),
  icon: PropTypes.string,
};

static defaultProps = {
  title: '',
  icon: '',
};

The above may be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! :)

};

render() {
let { title, icon } = this.props;
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let -> const

@Gargron Gargron merged commit 798b0fc into mastodon:master Sep 20, 2017
rutan pushed a commit to rutan/mastodon that referenced this pull request Oct 11, 2017
* Reduce wasted renders for column_loading.js

* Use defaultProps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants