-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SIEM] Fix unnecessary re-renders on the Overview page #56587
Conversation
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" |
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.
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.
typings/fast_deep_equal.d.ts
Outdated
*/ | ||
|
||
declare const equal: (a: any, b: any) => boolean; | ||
export = equal; |
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.
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.
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.
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); |
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.
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} />} |
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.
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 */ |
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.
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.
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.
I reviewed the code, I did not see anything weird there. However, give me some time to test it locally
@@ -131,8 +131,4 @@ export const BarChartComponent = ({ | |||
); | |||
}; | |||
|
|||
BarChartComponent.displayName = 'BarChartComponent'; |
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.
do the recent tooling changes make explicitly setting displayName
unnecessary in cases like this?
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.
Yes with @patrykkopycinski npm library
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.
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, { |
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.
🦅 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'; |
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.
it appears the //
may be missing es6
, i.e.:
import deepEqual from 'fast-deep-equal/es6/react';
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.
Thank you @patrykkopycinski for the performance improvements in this PR, and for the knowledge sharing and demo with the team today! 🙏
LGTM 🚀
…ibana into chore/siem-deep-equal
after reverting changes for using |
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.
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
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…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
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. |
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
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 #51926Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers