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 memoizedViewBoundsFunc = memoizeOne(createViewedBoundsFunc, isEqual);
|
||||
const memoizedGetClipping = memoizeOne(getClipping, isEqual);
|
||||
const memoizedChildSpansMap = memoizeOne(childSpansMap);
|
||||
|
||||
// export from tests
|
||||
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() {
|
||||
const lv = this.listView;
|
||||
if (!lv) {
|
||||
@ -461,10 +479,10 @@ export class UnthemedVirtualizedTraceView extends React.Component<VirtualizedTra
|
||||
// This function called recursively to find all descendants of a span
|
||||
const findAllDescendants = (currentChildSpanIds: string[]) => {
|
||||
currentChildSpanIds.forEach((eachId) => {
|
||||
const currentChildSpan = trace.spans.find((a) => a.spanID === eachId)!;
|
||||
if (currentChildSpan.hasChildren) {
|
||||
allChildSpanIds.push(...currentChildSpan.childSpanIds);
|
||||
findAllDescendants(currentChildSpan.childSpanIds);
|
||||
const childrenOfCurrent = this.getChildSpansMap().get(eachId);
|
||||
if (childrenOfCurrent?.length) {
|
||||
allChildSpanIds.push(...childrenOfCurrent);
|
||||
findAllDescendants(childrenOfCurrent);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user