-
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
[WIP] - Improve performance #212173
base: main
Are you sure you want to change the base?
[WIP] - Improve performance #212173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import type { FC } from 'react'; | ||
import type { KibanaPageTemplateProps } from '@kbn/shared-ux-page-kibana-template'; | ||
import { useKibana } from '../../lib/kibana'; | ||
|
@@ -15,14 +15,18 @@ import { useKibana } from '../../lib/kibana'; | |
* | ||
* The `template` prop can be used to alter the page layout for a given plugin route / all routes within a plugin - depending on the nesting. | ||
*/ | ||
export const PluginTemplateWrapper: FC<KibanaPageTemplateProps> = ({ children, ...rest }) => { | ||
const { | ||
services: { | ||
securityLayout: { getPluginWrapper }, | ||
}, | ||
} = useKibana(); | ||
export const PluginTemplateWrapper: FC<KibanaPageTemplateProps> = React.memo( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent multiple re-renders of the UI due to reference changes |
||
({ children, ...rest }) => { | ||
const { | ||
services: { | ||
securityLayout: { getPluginWrapper }, | ||
}, | ||
} = useKibana(); | ||
|
||
const Wrapper = getPluginWrapper(); | ||
const Wrapper = useMemo(() => getPluginWrapper(), [getPluginWrapper]); | ||
|
||
return <Wrapper {...rest}>{children}</Wrapper>; | ||
}; | ||
return <Wrapper {...rest}>{children}</Wrapper>; | ||
} | ||
); | ||
|
||
PluginTemplateWrapper.displayName = 'PluginTemplateWrapper'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,11 @@ import type { ENDPOINT_FIELDS_SEARCH_STRATEGY } from '../../../../common/endpoin | |
export type { BrowserFields }; | ||
|
||
export function getAllBrowserFields(browserFields: BrowserFields): Array<Partial<FieldSpec>> { | ||
const result: Array<Partial<FieldSpec>> = []; | ||
let result: Array<Partial<FieldSpec>> = []; | ||
for (const namespace of Object.values(browserFields)) { | ||
if (namespace.fields) { | ||
result.push(...Object.values(namespace.fields)); | ||
const namespaceFields = Object.values(namespace.fields); | ||
result = result.concat(namespaceFields); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same improvement here: https://github.com/elastic/kibana/pull/212173/files#r1966451342 |
||
} | ||
} | ||
return result; | ||
|
@@ -36,9 +37,11 @@ export function getAllBrowserFields(browserFields: BrowserFields): Array<Partial | |
* @param browserFields | ||
* @returns | ||
*/ | ||
export const getAllFieldsByName = ( | ||
browserFields: BrowserFields | ||
): { [fieldName: string]: Partial<FieldSpec> } => keyBy('name', getAllBrowserFields(browserFields)); | ||
export const getAllFieldsByName = memoizeOne( | ||
(browserFields: BrowserFields): { [fieldName: string]: Partial<FieldSpec> } => | ||
keyBy('name', getAllBrowserFields(browserFields)), | ||
(newArgs, lastArgs) => newArgs[0] === lastArgs[0] | ||
); | ||
|
||
export const getIndexFields = memoizeOne( | ||
(title: string, fields: IIndexPatternFieldList): DataViewBase => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,6 @@ export const useSourcererDataView = ( | |
); | ||
|
||
const [legacyPatterns, setLegacyPatterns] = useState<string[]>([]); | ||
|
||
const [indexPatternsLoading, fetchIndexReturn] = useFetchIndex(legacyPatterns); | ||
|
||
const legacyDataView: Omit<SourcererDataView, 'id'> & { id: string | null } = useMemo( | ||
|
@@ -67,10 +66,10 @@ export const useSourcererDataView = ( | |
if (selectedDataView == null || missingPatterns.length > 0) { | ||
// old way of fetching indices, legacy timeline | ||
setLegacyPatterns(selectedPatterns); | ||
} else { | ||
} else if (legacyPatterns.length > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new |
||
setLegacyPatterns([]); | ||
} | ||
}, [missingPatterns, selectedDataView, selectedPatterns]); | ||
}, [legacyPatterns.length, missingPatterns, selectedDataView, selectedPatterns]); | ||
|
||
const sourcererDataView = useMemo(() => { | ||
const _dv = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,18 @@ | |
import type { ComponentProps, ReactElement } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { RootDragDropProvider } from '@kbn/dom-drag-drop'; | ||
import { useGetScopedSourcererDataView } from '../../../../sourcerer/components/use_get_sourcerer_data_view'; | ||
import { DataViewErrorComponent } from '../../../../common/components/with_data_view/data_view_error'; | ||
import { StyledTableFlexGroup, StyledUnifiedTableFlexItem } from '../unified_components/styles'; | ||
import { UnifiedTimeline } from '../unified_components'; | ||
import { defaultUdtHeaders } from './column_headers/default_headers'; | ||
import { SourcererScopeName } from '../../../../sourcerer/store/model'; | ||
|
||
export interface UnifiedTimelineBodyProps extends ComponentProps<typeof UnifiedTimeline> { | ||
header: ReactElement; | ||
} | ||
|
||
export const UnifiedTimelineBody = (props: UnifiedTimelineBodyProps) => { | ||
export const UnifiedTimelineBody = (props: Omit<UnifiedTimelineBodyProps, 'dataView'>) => { | ||
const { | ||
header, | ||
isSortEnabled, | ||
|
@@ -37,7 +40,9 @@ export const UnifiedTimelineBody = (props: UnifiedTimelineBodyProps) => { | |
leadingControlColumns, | ||
onUpdatePageIndex, | ||
} = props; | ||
|
||
const dataView = useGetScopedSourcererDataView({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
sourcererScope: SourcererScopeName.timeline, | ||
}); | ||
const columnsHeader = useMemo(() => columns ?? defaultUdtHeaders, [columns]); | ||
|
||
return ( | ||
|
@@ -48,26 +53,31 @@ export const UnifiedTimelineBody = (props: UnifiedTimelineBodyProps) => { | |
data-test-subj="unifiedTimelineBody" | ||
> | ||
<RootDragDropProvider> | ||
<UnifiedTimeline | ||
columns={columnsHeader} | ||
rowRenderers={rowRenderers} | ||
isSortEnabled={isSortEnabled} | ||
timelineId={timelineId} | ||
itemsPerPage={itemsPerPage} | ||
itemsPerPageOptions={itemsPerPageOptions} | ||
sort={sort} | ||
events={events} | ||
refetch={refetch} | ||
dataLoadingState={dataLoadingState} | ||
totalCount={totalCount} | ||
onFetchMoreRecords={onFetchMoreRecords} | ||
activeTab={activeTab} | ||
updatedAt={updatedAt} | ||
isTextBasedQuery={false} | ||
trailingControlColumns={trailingControlColumns} | ||
leadingControlColumns={leadingControlColumns} | ||
onUpdatePageIndex={onUpdatePageIndex} | ||
/> | ||
{dataView ? ( | ||
<UnifiedTimeline | ||
columns={columnsHeader} | ||
dataView={dataView} | ||
rowRenderers={rowRenderers} | ||
isSortEnabled={isSortEnabled} | ||
timelineId={timelineId} | ||
itemsPerPage={itemsPerPage} | ||
itemsPerPageOptions={itemsPerPageOptions} | ||
sort={sort} | ||
events={events} | ||
refetch={refetch} | ||
dataLoadingState={dataLoadingState} | ||
totalCount={totalCount} | ||
onFetchMoreRecords={onFetchMoreRecords} | ||
activeTab={activeTab} | ||
updatedAt={updatedAt} | ||
isTextBasedQuery={false} | ||
trailingControlColumns={trailingControlColumns} | ||
leadingControlColumns={leadingControlColumns} | ||
onUpdatePageIndex={onUpdatePageIndex} | ||
/> | ||
) : ( | ||
<DataViewErrorComponent /> | ||
)} | ||
</RootDragDropProvider> | ||
</StyledUnifiedTableFlexItem> | ||
</StyledTableFlexGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { createContext } from 'react'; | ||
|
||
export const TimelineContext = createContext<{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor code re-organization |
||
timelineId: string | null; | ||
}>({ timelineId: null }); |
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.
At scale this was crashing the browser (tested with 500k fields):

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.