-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Lens] Add lens editor performance metrics #163089
Changes from 9 commits
230a39c
52f5b7f
478bc14
b7d903e
d7095c2
77b1065
aeafebe
bfb92f4
7bfd784
84c0ec8
bff8f62
f19dd13
83b09a9
23ee3ad
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 |
---|---|---|
|
@@ -99,4 +99,4 @@ | |
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,10 @@ export const WorkspacePanel = React.memo(function WorkspacePanel(props: Workspac | |
); | ||
}); | ||
|
||
const log = (...messages: Array<string | number>) => { | ||
// console.log(...messages); | ||
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. uncomment for review |
||
}; | ||
|
||
// Exported for testing purposes only. | ||
export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | ||
framePublicAPI, | ||
|
@@ -170,7 +174,10 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | |
errors: [], | ||
}); | ||
|
||
const initialRenderComplete = useRef<boolean>(); | ||
const initialVisualizationRenderComplete = useRef<boolean>(false); | ||
|
||
// NOTE: This does not reflect the actual visualization render | ||
const initialWorkspaceRenderComplete = useRef<boolean>(); | ||
|
||
const renderDeps = useRef<{ | ||
datasourceMap: DatasourceMap; | ||
|
@@ -192,8 +199,20 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | |
dataViews, | ||
}; | ||
|
||
// NOTE: initialRenderTime is only set once when the component mounts | ||
const initialRenderTime = useRef<number>(performance.now()); | ||
const dataReceivedTime = useRef<number>(0); | ||
|
||
const onRender$ = useCallback(() => { | ||
if (renderDeps.current) { | ||
if (!initialVisualizationRenderComplete.current) { | ||
initialVisualizationRenderComplete.current = true; | ||
// NOTE: this metric is only repored for an initial editor load of a pre-existing visualization | ||
log( | ||
'initial visualization took to render after data received', | ||
performance.now() - dataReceivedTime.current | ||
); | ||
} | ||
const datasourceEvents = Object.values(renderDeps.current.datasourceMap).reduce<string[]>( | ||
(acc, datasource) => { | ||
if (!renderDeps.current!.datasourceStates[datasource.id]) return []; | ||
|
@@ -232,6 +251,12 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | |
const onData$ = useCallback( | ||
(_data: unknown, adapters?: Partial<DefaultInspectorAdapters>) => { | ||
if (renderDeps.current) { | ||
dataReceivedTime.current = performance.now(); | ||
if (!initialVisualizationRenderComplete.current) { | ||
// NOTE: this metric is only repored for an initial editor load of a pre-existing visualization | ||
log('initial data took to arrive', dataReceivedTime.current - initialRenderTime.current); | ||
} | ||
|
||
const [defaultLayerId] = Object.keys(renderDeps.current.datasourceLayers); | ||
const datasource = Object.values(renderDeps.current.datasourceMap)[0]; | ||
const datasourceState = Object.values(renderDeps.current.datasourceStates)[0].state; | ||
|
@@ -276,7 +301,8 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | |
[addUserMessages, dispatchLens, plugins.data.search] | ||
); | ||
|
||
const shouldApplyExpression = autoApplyEnabled || !initialRenderComplete.current || triggerApply; | ||
const shouldApplyExpression = | ||
autoApplyEnabled || !initialWorkspaceRenderComplete.current || triggerApply; | ||
const activeVisualization = visualization.activeId | ||
? visualizationMap[visualization.activeId] | ||
: null; | ||
|
@@ -389,9 +415,9 @@ export const InnerWorkspacePanel = React.memo(function InnerWorkspacePanel({ | |
// null signals an empty workspace which should count as an initial render | ||
if ( | ||
(expressionExists || localState.expressionToRender === null) && | ||
!initialRenderComplete.current | ||
!initialWorkspaceRenderComplete.current | ||
) { | ||
initialRenderComplete.current = true; | ||
initialWorkspaceRenderComplete.current = true; | ||
} | ||
}, [expressionExists, localState.expressionToRender]); | ||
|
||
|
@@ -687,6 +713,12 @@ export const VisualizationWrapper = ({ | |
// Used for reporting | ||
const { isRenderComplete, hasDynamicError, setIsRenderComplete, setDynamicError, nodeRef } = | ||
useReportingState(errors); | ||
|
||
const onRenderHandler = useCallback(() => { | ||
setIsRenderComplete(true); | ||
onRender$(); | ||
}, [setIsRenderComplete, onRender$]); | ||
Comment on lines
+724
to
+727
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. Important to memoize—multiple subscriptions in |
||
|
||
const searchContext: ExecutionContextSearch = useMemo( | ||
() => ({ | ||
query: context.query, | ||
|
@@ -782,10 +814,7 @@ export const VisualizationWrapper = ({ | |
onEvent={onEvent} | ||
hasCompatibleActions={hasCompatibleActions} | ||
onData$={onData$} | ||
onRender$={() => { | ||
setIsRenderComplete(true); | ||
onRender$(); | ||
}} | ||
onRender$={onRenderHandler} | ||
inspectorAdapters={lensInspector.adapters} | ||
executionContext={executionContext} | ||
renderMode="edit" | ||
|
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.
uncomment for review