Skip to content

Improve performance when expanding/collapsing span details #2716

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

Merged
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 @@ -17,6 +17,7 @@ import cx from 'classnames';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import _isEqual from 'lodash/isEqual';
import _groupBy from 'lodash/groupBy';

// import { History as RouterHistory, Location } from 'history';

Expand Down Expand Up @@ -199,6 +200,9 @@ function mergeChildrenCriticalPath(
const memoizedGenerateRowStates = memoizeOne(generateRowStatesFromTrace);
const memoizedViewBoundsFunc = memoizeOne(createViewedBoundsFunc, _isEqual);
const memoizedGetCssClasses = memoizeOne(getCssClasses, _isEqual);
const memoizedCriticalPathsBySpanID = memoizeOne((criticalPath: criticalPathSection[]) =>
_groupBy(criticalPath, x => x.spanId)
);

// export from tests
export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceViewProps> {
Expand Down Expand Up @@ -374,6 +378,20 @@ export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceVi
: this.renderSpanBarRow(span, spanIndex, key, style, attrs);
};

getCriticalPathSections(
isCollapsed: boolean,
trace: Trace,
spanID: string,
criticalPath: criticalPathSection[]
) {
if (isCollapsed) {
return mergeChildrenCriticalPath(trace, spanID, criticalPath);
}

const pathBySpanID = memoizedCriticalPathsBySpanID(criticalPath);
return spanID in pathBySpanID ? pathBySpanID[spanID] : [];
}

renderSpanBarRow(span: Span, spanIndex: number, key: string, style: React.CSSProperties, attrs: object) {
const { spanID } = span;
const { serviceName } = span.process;
Expand All @@ -396,9 +414,7 @@ export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceVi
const isDetailExpanded = detailStates.has(spanID);
const isMatchingFilter = findMatchesIDs ? findMatchesIDs.has(spanID) : false;
const showErrorIcon = isErrorSpan(span) || (isCollapsed && spanContainsErredSpan(trace.spans, spanIndex));
const criticalPathSections = isCollapsed
? mergeChildrenCriticalPath(trace, spanID, criticalPath)
: criticalPath.filter(each => each.spanId === spanID);
const criticalPathSections = this.getCriticalPathSections(isCollapsed, trace, spanID, criticalPath);
// Check for direct child "server" span if the span is a "client" span.
let rpc = null;
if (isCollapsed) {
Expand Down
Loading