Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function getCssClasses(currentViewRange: [number, number]) {
});
}

const memoizedSpanByID = memoizeOne((spans: Span[]) => new Map(spans.map(x => [x.spanID, x])));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but I am not sure if there is a good place for this data.

Creating a Map or a Set should not have measurable impact on performance, because it is usually done once per trace.
Also, if any refactoring is needed, then it would probably be best to do this in another PR.


function mergeChildrenCriticalPath(
trace: Trace,
spanID: string,
Expand All @@ -168,23 +170,23 @@ function mergeChildrenCriticalPath(
return [];
}
// Define an array to store the IDs of the span and its descendants (if the span is collapsed)
const allRequiredSpanIds = [spanID];
const allRequiredSpanIds = new Set<string>([spanID]);

// If the span is collapsed, recursively find all of its descendants.
const findAllDescendants = (currentChildSpanIds: string[]) => {
const findAllDescendants = (currentChildSpanIds: Set<string>) => {
currentChildSpanIds.forEach(eachId => {
const currentChildSpan = trace.spans.find(a => a.spanID === eachId)!;
const currentChildSpan = memoizedSpanByID(trace.spans).get(eachId)!;
if (currentChildSpan.hasChildren) {
allRequiredSpanIds.push(...currentChildSpan.childSpanIds);
findAllDescendants(currentChildSpan.childSpanIds);
currentChildSpan.childSpanIds.forEach(x => allRequiredSpanIds.add(x));
findAllDescendants(new Set<string>(currentChildSpan.childSpanIds));
}
});
};
findAllDescendants(allRequiredSpanIds);

const criticalPathSections: criticalPathSection[] = [];
criticalPath.forEach(each => {
if (allRequiredSpanIds.includes(each.spanId)) {
if (allRequiredSpanIds.has(each.spanId)) {
if (criticalPathSections.length !== 0 && each.section_end === criticalPathSections[0].section_start) {
// Merge Critical Paths if they are consecutive
criticalPathSections[0].section_start = each.section_start;
Expand Down
Loading