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

[SIEM] Fix unnecessary re-renders on the Overview page #56587

Merged

Conversation

patrykkopycinski
Copy link
Contributor

Summary

With help of why-did-you-render I was able to track and fix some of the unnecessary re-renders in our app.
As a first step, I've focused on the Overview page as it's our main page

Before:
On the initial load of Overview page we have ~155 unnecessary re-renders
Screenshot 2020-02-02 at 16 13 48

After:
I was able to reduce this number to 14.
I've decided to not track redux connect wrappers as in 7.7 we will migrate to hooks.
I think I have found bug in charts library that causes unnecessary re-renders, I will confirm that this week
WithSource will be resolved after me migrate to #51926

Screenshot 2020-02-02 at 16 14 01

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@@ -13,7 +13,8 @@
"devDependencies": {
"@types/lodash": "^4.14.110",
"@types/js-yaml": "^3.12.1",
"@types/react-beautiful-dnd": "^11.0.4"
"@types/react-beautiful-dnd": "^11.0.4",
"@welldone-software/why-did-you-render": "^4.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this up to x-pack/package.json as we are suppose to keep our package.json within SIEM to a minimum as per the last time we talked to core team members.

*/

declare const equal: (a: any, b: any) => boolean;
export = equal;
Copy link
Contributor

@FrankHassanabad FrankHassanabad Feb 3, 2020

Choose a reason for hiding this comment

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

I would add a comment where this came from.

Looks like it is from one of these files?

epoberezkin/fast-deep-equal@f0e3dc1

and why we have to have it here and cannot use regular TypeScript without additional "cruft" and duplication for the next maintainer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I see this above:

/*
  TODO: Remove after https://github.com/epoberezkin/fast-deep-equal/pull/48
  is merged and fast-deep-equal version is bumped
*/

I think you are good!

@@ -27,6 +31,8 @@ export const formatSignalsData = (
}, []);
};

export const memoFormatSignalsData = memoizeOne(formatSignalsData, deepEqual);
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing this here, can we do the memoization where we do the fetch? So when other engineers will use the hooks will be already memoized.

render={({ location, match }) => (
<HostsContainer location={location} url={match.url} />
)}
render={({ match }) => <HostsContainer url={match.url} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering here since we have the new version of react-router, we might be able to use their hook to get the value inside of the component without the props.

@@ -12,6 +12,16 @@ import { NotFoundPage } from './pages/404';
import { HomePage } from './pages/home';
import { ManageRoutesSpy } from './utils/route/manage_spy_routes';

/* Uncomment only during debugging */
Copy link
Contributor

@XavierM XavierM Feb 5, 2020

Choose a reason for hiding this comment

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

do we want to keep it like that or adding it into a read.me. So it is easy to find it later on and maybe explain there how to find re-render problems and how to resolve them.

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

I reviewed the code, I did not see anything weird there. However, give me some time to test it locally

…ep-equal

# Conflicts:
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx
@@ -131,8 +131,4 @@ export const BarChartComponent = ({
);
};

BarChartComponent.displayName = 'BarChartComponent';
Copy link
Contributor

Choose a reason for hiding this comment

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

do the recent tooling changes make explicitly setting displayName unnecessary in cases like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes with @patrykkopycinski npm library

Copy link
Contributor Author

@patrykkopycinski patrykkopycinski Feb 6, 2020

Choose a reason for hiding this comment

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

the library wasn't added @XavierM :( but the good news is that if we declare component as
const component:React.FC<>
and then declare
const MemoComponent = React.memo(Component)
it will get the displayName automatically

@@ -117,8 +128,10 @@ const mapStateToProps = (state: State, { timelineId }: OwnProps) => {
return { dataProviders, show, width };
};

export const Flyout = connect(mapStateToProps, {
Copy link
Contributor

Choose a reason for hiding this comment

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

🦅 this is a subtle one! looking forward to your PR that updates our redux deps!

@@ -8,6 +8,7 @@ import { EuiFlexGroup } from '@elastic/eui';
import { getOr, isEmpty } from 'lodash/fp';
import React from 'react';
import styled from 'styled-components';
import deepEqual from 'fast-deep-equal//react';
Copy link
Contributor

Choose a reason for hiding this comment

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

it appears the // may be missing es6, i.e.:

import deepEqual from 'fast-deep-equal/es6/react';

Copy link
Contributor

@andrew-goldstein andrew-goldstein left a comment

Choose a reason for hiding this comment

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

Thank you @patrykkopycinski for the performance improvements in this PR, and for the knowledge sharing and demo with the team today! 🙏
LGTM 🚀

@patrykkopycinski patrykkopycinski requested a review from a team as a code owner February 6, 2020 01:12
@patrykkopycinski
Copy link
Contributor Author

after reverting changes for using deepEqual in memo() we're back to ~220 re-renders

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for all the hard work. I still think that it will be nice to see the change when we move away from our render props. I will bet the number will go down

…ep-equal

# Conflicts:
#	package.json
#	packages/kbn-ui-shared-deps/package.json
#	x-pack/legacy/plugins/siem/public/components/auto_sizer/index.tsx
#	x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx
#	x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx
#	x-pack/legacy/plugins/siem/public/components/drag_and_drop/draggable_wrapper.tsx
#	x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx
#	x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx
#	x-pack/legacy/plugins/siem/public/components/flyout/index.tsx
#	x-pack/legacy/plugins/siem/public/components/flyout/pane/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/hosts/authentications_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/hosts/hosts_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/hosts/uncommon_process_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.tsx
#	x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx
#	x-pack/legacy/plugins/siem/public/components/timeline/index.tsx
#	x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx
#	x-pack/legacy/plugins/siem/public/components/timeline/refetch_timeline.tsx
#	x-pack/legacy/plugins/siem/public/components/url_state/use_url_state.tsx
#	x-pack/legacy/plugins/siem/public/containers/global_time/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/home/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.tsx
#	x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx
#	x-pack/legacy/plugins/siem/public/pages/hosts/hosts_tabs.tsx
#	x-pack/legacy/plugins/siem/public/pages/network/navigation/network_routes.tsx
#	x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx
#	yarn.lock
…ep-equal

# Conflicts:
#	x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx
#	x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@patrykkopycinski patrykkopycinski merged commit 418c44a into elastic:master Feb 25, 2020
@patrykkopycinski patrykkopycinski deleted the chore/siem-deep-equal branch February 25, 2020 14:00
patrykkopycinski added a commit to patrykkopycinski/kibana that referenced this pull request Feb 25, 2020
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 25, 2020
…re/files-and-filetree

* 'master' of github.com:elastic/kibana: (174 commits)
  [SIEM] Fix unnecessary re-renders on the Overview page (elastic#56587)
  Don't mutate error message (elastic#58452)
  Fix service map popover transaction duration (elastic#58422)
  [ML] Adding filebeat config to file dataviz (elastic#58152)
  [Uptime] Improve refresh handling when generating test data (elastic#58285)
  [Logs / Metrics UI] Remove path prefix from ViewSourceConfigur… (elastic#58238)
  [ML] Functional tests - adjust classification model memory (elastic#58445)
  [ML] Use event.timezone instead of beat.timezone in file upload (elastic#58447)
  [Logs UI] Unskip and stabilitize log column configuration tests (elastic#58392)
  [Telemetry] Separate the license retrieval from the stats in the usage collectors (elastic#57332)
  hide welcome screen for cloud (elastic#58371)
  Move src/legacy/ui/public/notify/app_redirect to kibana_legacy (elastic#58127)
  [ML] Functional tests - stabilize typing during df analytics creation (elastic#58227)
  fix short url in spaces (elastic#58313)
  [SIEM] Upgrades cypress to version 4.0.2 (elastic#58400)
  [Index management] Move to new platform "plugins" folder (elastic#58109)
  [kbn/optimizer] disable parallelization in terser plugin (elastic#58396)
  [Uptime] Delete useless try...catch blocks (elastic#58263)
  [Uptime] Use scripted metric for snapshot calculation (elastic#58247) (elastic#58389)
  [APM] Stabilize agent configuration API (elastic#57767)
  ...

# Conflicts:
#	src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Feb 26, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes Team:SIEM v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants