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

Fix: Prevent some needless re-rendering in high-level components #31958

Merged
merged 11 commits into from
Mar 2, 2019

Conversation

w33ble
Copy link
Contributor

@w33ble w33ble commented Feb 25, 2019

In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change.

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

  • Workpad, WorkpadHeader, and FullscreenControl would always re-render because the hotkey handler function was always re-created
  • Workpad would re-render when the workpad's name changed
    • We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
    • Page title updating moved to middleware so the component doesn't need that value
  • AssetManager would always re-render if the parent re-rendered because it always created a new state value in mapStateToProps
  • make Workpad and Toolbar pure, they take no props and this helps stop some re-rendering

@w33ble w33ble added WIP Work in progress Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas labels Feb 25, 2019
@w33ble w33ble requested a review from a team as a code owner February 25, 2019 21:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-canvas

@w33ble w33ble force-pushed the fix/workpad-rename-lag branch from 3452677 to a6ecfad Compare February 25, 2019 21:07
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@w33ble w33ble force-pushed the fix/workpad-rename-lag branch from a6ecfad to a6e2ded Compare February 25, 2019 23:27
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@w33ble w33ble changed the title Fix: workpad rename lag Fix: Prevent some needless re-rendering in high-level components Feb 28, 2019
@w33ble w33ble added performance and removed WIP Work in progress labels Feb 28, 2019
allow setting the keyhandler function on the component instance
flat state prevents re-renders, and not using the workpad name prevents re-renders. plus, side effects should happen in middleware
help prevent re-renders on function redefinition
don't mutate values in mapStateToProps, so the connect function retains pure functionality
neither take props, so this stops some re-rendering
@w33ble w33ble force-pushed the fix/workpad-rename-lag branch from 3168ff6 to 82525ac Compare February 28, 2019 21:47
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -9,6 +9,12 @@ import PropTypes from 'prop-types';
import { Shortcuts } from 'react-shortcuts';

export class FullscreenControl extends React.PureComponent {
keyHandler = action => {
if (action === 'FULLSCREEN' || (this.props.isFullscreen && action === 'FULLSCREEN_EXIT')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we make these consts?

Copy link
Contributor Author

@w33ble w33ble Mar 1, 2019

Choose a reason for hiding this comment

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

I don't understand what you're asking for here.

Is this what you're looking for?

export class FullscreenControl extends React.PureComponent {
   keyHandler = action => {
-    if (action === 'FULLSCREEN' || (this.props.isFullscreen && action === 'FULLSCREEN_EXIT')) {
+    const enterFullscreen = action === 'FULLSCREEN';
+    const exitFullscreen = this.props.isFullscreen && action === 'FULLSCREEN_EXIT';
+
+    if (enterFullscreen || exitFullscreen) {
       this.toggleFullscreen();
     }
   };

<Shortcuts name="EDITOR" handler={keyHandler} targetNodeSelector="body" global />
)}
const bufferStyle = {
height: isFullscreen ? height : height + 32,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we make 32 a const? It will help explain what it is and why it's necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why that value is there, I didn't change that. I'll try figuring it out though.

Copy link
Contributor

@cqliu1 cqliu1 left a comment

Choose a reason for hiding this comment

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

Excellent refactors! I threw a bunch of console.logs in all the render functions effected, and there are significantly less unnecessary re-renders when making changes to the workpad name, size, etc. I only have one requested change.

@@ -63,84 +69,85 @@ export const Workpad = props => {
}
};

setDocTitle(workpad.name);
render() {
console.log('Workpad render');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice spot!


next(action);

// This middleware updates the page title when the workpad name changes
if (getWorkpadName(getState()) !== oldName) {
setDocTitle(getWorkpadName(getState()));
Copy link
Contributor

Choose a reason for hiding this comment

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

++ to checking the name changed before setting the doc title. This is a much better place to do the title update

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@w33ble w33ble merged commit 7d8dbc6 into elastic:master Mar 2, 2019
w33ble added a commit to w33ble/kibana that referenced this pull request Mar 2, 2019
…stic#31958)

In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
w33ble added a commit to w33ble/kibana that referenced this pull request Mar 2, 2019
…stic#31958)

In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
w33ble added a commit to w33ble/kibana that referenced this pull request Mar 2, 2019
…stic#31958)

In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
w33ble added a commit that referenced this pull request Mar 5, 2019
) (#32359)

In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
w33ble added a commit that referenced this pull request Mar 5, 2019
) (#32358)

In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
w33ble added a commit that referenced this pull request Mar 5, 2019
) (#32357)

In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. 

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
monfera pushed a commit to monfera/kibana that referenced this pull request Mar 8, 2019
…stic#31958)

In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change.

I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:

- `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created
- `Workpad` would re-render when the workpad's name changed
  - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes
  - Page title updating moved to middleware so the component doesn't need that value
- `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps`
- make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering

(cherry picked from commit 7d8dbc6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v6.7.0 v7.0.0 v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants