Skip to content

Commit 6fbbbcb

Browse files
Reduce load time of trace page by deferring critical path tooltip (#2718)
~I am opening this PR without an issue, I understand that is might not be an acceptable change, feel free to close this PR if you don't agree with this change.~ Improve performance (~300ms for 500 spans) by loading tooltip only on hover * Related issue in antd repo ant-design/ant-design#48468 * My other changes which improve performance related to critical path #2716 * Towards #645, to improve general performance with large amount of spans ## Before ![criticalPathTooltip](https://github.com/user-attachments/assets/908b6279-a3b8-4446-a08b-386220e22141) ## After ![criticalPathNoTooltip](https://github.com/user-attachments/assets/e7eb14e2-6acd-4f6d-94cb-ce1d82515e02) --------- Signed-off-by: Damian Maslanka <[email protected]>
1 parent 004c803 commit 6fbbbcb

File tree

2 files changed

+67
-19
lines changed

2 files changed

+67
-19
lines changed

packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanBar.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,27 @@ describe('<SpanBar>', () => {
106106
const wrapper = render(<SpanBar {...newProps} />);
107107
expect(wrapper.getAllByTestId('SpanBar--criticalPath').length).toEqual(1);
108108
});
109+
110+
it('Critical Path tooltip is visible on hover', () => {
111+
const newProps = {
112+
...props,
113+
criticalPath: [
114+
{
115+
spanId: 'Test-SpanId',
116+
section_start: 10,
117+
section_end: 20,
118+
},
119+
],
120+
getViewedBounds: () => ({ start: 0.1, end: 0.5 }),
121+
};
122+
render(<SpanBar {...newProps} />);
123+
124+
const criticalPathEl = screen.getByTestId('SpanBar--criticalPath');
125+
fireEvent.mouseEnter(criticalPathEl);
126+
127+
const criticalPathTooltip = screen.getByRole('tooltip');
128+
expect(criticalPathTooltip.textContent).toMatch(
129+
'A segment on the critical path of the overall trace/request/workflow.'
130+
);
131+
});
109132
});

packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanBar.tsx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ function toPercentInDecimal(value: number) {
5454
return `${value * 100}%`;
5555
}
5656

57+
function SpanBarCriticalPath(props: { criticalPathViewStart: number; criticalPathViewEnd: number }) {
58+
const [shouldLoadTooltip, setShouldLoadTooltip] = useState(false);
59+
60+
const criticalPath = (
61+
<div
62+
data-testid="SpanBar--criticalPath"
63+
className="SpanBar--criticalPath"
64+
onMouseEnter={() => setShouldLoadTooltip(true)}
65+
style={{
66+
background: 'black',
67+
left: toPercentInDecimal(props.criticalPathViewStart),
68+
width: toPercentInDecimal(props.criticalPathViewEnd - props.criticalPathViewStart),
69+
}}
70+
/>
71+
);
72+
73+
// Load tooltip only when hovering over critical path segment
74+
// to reduce initial load time of trace page by ~300ms for 500 spans
75+
if (shouldLoadTooltip) {
76+
return (
77+
<Tooltip
78+
placement="top"
79+
// defaultOpen is needed to show the tooltip when shouldLoadTooltip changes to true
80+
defaultOpen
81+
title={
82+
<div>
83+
A segment on the <em>critical path</em> of the overall trace/request/workflow.
84+
</div>
85+
}
86+
>
87+
{criticalPath}
88+
</Tooltip>
89+
);
90+
}
91+
92+
return criticalPath;
93+
}
94+
5795
function SpanBar(props: TCommonProps) {
5896
const {
5997
criticalPath,
@@ -145,26 +183,13 @@ function SpanBar(props: TCommonProps) {
145183
const criticalPathViewStart = critcalPathViewBounds.start;
146184
const criticalPathViewEnd = critcalPathViewBounds.end;
147185
const key = `${each.spanId}-${index}`;
186+
148187
return (
149-
<Tooltip
150-
placement="top"
151-
title={
152-
<div>
153-
A segment on the <em>critical path</em> of the overall trace/request/workflow.
154-
</div>
155-
}
156-
>
157-
<div
158-
key={key}
159-
data-testid="SpanBar--criticalPath"
160-
className="SpanBar--criticalPath"
161-
style={{
162-
background: 'black',
163-
left: toPercentInDecimal(criticalPathViewStart),
164-
width: toPercentInDecimal(criticalPathViewEnd - criticalPathViewStart),
165-
}}
166-
/>
167-
</Tooltip>
188+
<SpanBarCriticalPath
189+
criticalPathViewStart={criticalPathViewStart}
190+
criticalPathViewEnd={criticalPathViewEnd}
191+
key={key}
192+
/>
168193
);
169194
})}
170195
</div>

0 commit comments

Comments
 (0)