mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Trace View: Fix issue with critical path performance (#77373)
Store child spans in Map for faster access on critical path render
This commit is contained in:
parent
06873f1be3
commit
41d394c594
@ -211,9 +211,23 @@ function generateRowStatesFromTrace(
|
|||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function childSpansMap(trace: Trace | TNil) {
|
||||||
|
const childSpansMap = new Map<string, string[]>();
|
||||||
|
if (!trace) {
|
||||||
|
return childSpansMap;
|
||||||
|
}
|
||||||
|
trace.spans.forEach((span) => {
|
||||||
|
if (span.childSpanIds.length) {
|
||||||
|
childSpansMap.set(span.spanID, span.childSpanIds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return childSpansMap;
|
||||||
|
}
|
||||||
|
|
||||||
const memoizedGenerateRowStates = memoizeOne(generateRowStatesFromTrace);
|
const memoizedGenerateRowStates = memoizeOne(generateRowStatesFromTrace);
|
||||||
const memoizedViewBoundsFunc = memoizeOne(createViewedBoundsFunc, isEqual);
|
const memoizedViewBoundsFunc = memoizeOne(createViewedBoundsFunc, isEqual);
|
||||||
const memoizedGetClipping = memoizeOne(getClipping, isEqual);
|
const memoizedGetClipping = memoizeOne(getClipping, isEqual);
|
||||||
|
const memoizedChildSpansMap = memoizeOne(childSpansMap);
|
||||||
|
|
||||||
// export from tests
|
// export from tests
|
||||||
export class UnthemedVirtualizedTraceView extends React.Component<VirtualizedTraceViewProps> {
|
export class UnthemedVirtualizedTraceView extends React.Component<VirtualizedTraceViewProps> {
|
||||||
@ -290,6 +304,10 @@ export class UnthemedVirtualizedTraceView extends React.Component<VirtualizedTra
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getChildSpansMap() {
|
||||||
|
return memoizedChildSpansMap(this.props.trace);
|
||||||
|
}
|
||||||
|
|
||||||
getAccessors() {
|
getAccessors() {
|
||||||
const lv = this.listView;
|
const lv = this.listView;
|
||||||
if (!lv) {
|
if (!lv) {
|
||||||
@ -461,10 +479,10 @@ export class UnthemedVirtualizedTraceView extends React.Component<VirtualizedTra
|
|||||||
// This function called recursively to find all descendants of a span
|
// This function called recursively to find all descendants of a span
|
||||||
const findAllDescendants = (currentChildSpanIds: string[]) => {
|
const findAllDescendants = (currentChildSpanIds: string[]) => {
|
||||||
currentChildSpanIds.forEach((eachId) => {
|
currentChildSpanIds.forEach((eachId) => {
|
||||||
const currentChildSpan = trace.spans.find((a) => a.spanID === eachId)!;
|
const childrenOfCurrent = this.getChildSpansMap().get(eachId);
|
||||||
if (currentChildSpan.hasChildren) {
|
if (childrenOfCurrent?.length) {
|
||||||
allChildSpanIds.push(...currentChildSpan.childSpanIds);
|
allChildSpanIds.push(...childrenOfCurrent);
|
||||||
findAllDescendants(currentChildSpan.childSpanIds);
|
findAllDescendants(childrenOfCurrent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user