Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[webapp-perf] Change anonymous inline function into a defined arrow function #484

Merged
merged 3 commits into from
Jan 9, 2018
Merged

[webapp-perf] Change anonymous inline function into a defined arrow function #484

merged 3 commits into from
Jan 9, 2018

Conversation

saturninoabril
Copy link
Member

Summary

  • Change anonymous inline functions into a defined arrow functions.
  • Make use of data-attr in storing information which serves as parameter of underlying function.

Note: This is second installment PR. Other PR submitted:

Ticket Link

[Please link the GitHub issue or Jira ticket this PR addresses.]

Checklist

  • Ran make check-style to check for style errors (required for all pull requests)
  • Ran make test to ensure unit and component tests passed
  • Added or updated unit tests (required for all new features)

@saturninoabril saturninoabril added the 2: Dev Review Requires review by a core commiter label Dec 18, 2017
@saturninoabril saturninoabril added this to the v4.6.0 milestone Dec 18, 2017
Copy link
Contributor

@enahum enahum left a comment

Choose a reason for hiding this comment

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

Pretty good just some minor issues

@@ -238,8 +242,8 @@ export default class MultiSelect extends React.Component {
onChange={this.onChange}
value={this.props.values}
valueRenderer={this.props.valueRenderer}
menuRenderer={() => null}
arrowRenderer={() => null}
menuRenderer={this.handleRender}
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for a function here, actually you could even remove the props

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried to remove those but

  • when menuRenderer is removed, the menu opened up as soon as the user access a component with MultiSelect (see screenshot)
    screen shot 2017-12-19 at 1 16 44 am
  • when arrowRenderer, an extra caret show up in the text box
    screen shot 2017-12-19 at 2 20 48 am

So I'll keep it that way.

@@ -354,6 +354,10 @@ export default class Navbar extends React.Component {
);
}

hideHeaderOverlay = () => {
this.refs.headerOverlay.hide();
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure the ref exists

Copy link
Contributor

Choose a reason for hiding this comment

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

what I mean here is that you should wrap this in an if statement like

hideHeaderOverlay = () => {
   if (this.refs.headerOverlay) {
      this.refs.headerOverlay.hide();
   }
};

Copy link
Member Author

Choose a reason for hiding this comment

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

I totally missed this one. Should be good now.

}

showChannelInviteModalButton = () => {
this.refs.channelInviteModalButton.show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@@ -144,6 +144,11 @@ export default class NewChannelModal extends React.PureComponent {
this.props.onDataChanged(newData);
}

handleOnURLChange = (e) => {
e.preventDefault();
this.props.onChangeURLPressed();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the prop required? If not check that is defined

@@ -211,6 +211,10 @@ export default class RhsRootPost extends React.Component {
});
}

getDotMenuRef = () => {
return this.refs.dotMenu;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too

Copy link
Member Author

Choose a reason for hiding this comment

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

Just add check at consuming component - EmojiPickerOverlay

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok here

Copy link
Contributor

@mkraft mkraft left a comment

Choose a reason for hiding this comment

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

@saturninoabril Have you ensured that every component you're changing the prop for fits one of the following:

a) Is a PureComponent, or
b) Is otherwise leveraging the prop with the non-inline function in its shouldComponentUpdate method?

The reason I ask is that if neither of those two cases are met then this performance optimization won't be realizing its full potential.

@saturninoabril
Copy link
Member Author

@mkraft This PR is mainly an outcome of what was discussed (and I supposed was agreed upon) last performance meeting about inline function. A similar follow up discussion here - https://pre-release.mattermost.com/core/pl/s4yfjinzhby38887au35yn8yzo
You're absolutely right about the 2 points, especially for those that renders standard element (e.g. <button onClick={this.handleClick}/>).
This PR might be a premature optimization (without actually presenting metrics) but I guess the key take away/pattern is to avoid inline function on render method that creates new function every time a component renders; an inline function without referential identity. Not to mention but doing so makes the function becomes easier to read/understand.

@mkraft
Copy link
Contributor

mkraft commented Dec 21, 2017

@saturninoabril I agree with what you're saying and maybe I should address the PureComponent discussion separately because certainly the changes in the PR have merit in their own right. Something for us to be aware of and I'm sure we'll address it in good time. Nice work 👍

@saturninoabril
Copy link
Member Author

Rebase to latest master and fix merge conflicts

@enahum
Copy link
Contributor

enahum commented Jan 4, 2018

@saturninoabril the rest of the code looks good, but I don't feel very comfortable to merge it for 4.6 as is very late in the game and that PR looks sensible and it does not give an important performance boost, what do you think?

@saturninoabril saturninoabril modified the milestones: v4.6.0, v4.7.0 Jan 4, 2018
@saturninoabril saturninoabril added Awaiting Submitter Action Blocked on the author 2: Dev Review Requires review by a core commiter and removed 2: Dev Review Requires review by a core commiter Awaiting Submitter Action Blocked on the author labels Jan 4, 2018
@saturninoabril saturninoabril added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core commiter labels Jan 5, 2018
@saturninoabril saturninoabril merged commit cd62ffb into mattermost:master Jan 9, 2018
@saturninoabril saturninoabril deleted the webapp-perf-04 branch January 12, 2018 17:24
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Feb 1, 2018
@lindalumitchell lindalumitchell added the Tests/Not Needed Does not require new release tests label Feb 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation Tests/Not Needed Does not require new release tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants