Commit 47ba7ab
authored
perf(dashboards): Fix slow re-render of ECharts objects (#103375)
This PR is part of the effort to improve how fast the Widget Builder
opens and runs. One of the reasons why it's slow is that the `Dashboard`
component (i.e., the literal dashboard and all its charts) underneath
the builder re-renders when it opens. This takes a long time because
each ECharts object takes ~50ms to re-draw. You can see this phase in
the screenshot, there are 5 charts on that page, so ~250ms delay.
<img width="524" height="316" alt="Screenshot 2025-11-14 at 11 19 10 AM"
src="https://github.com/user-attachments/assets/3dfc4b7f-492c-400c-bc29-0ac692b36842"
/>
On re-render, `echarts-for-react` calls `componentDidUpdate` and in
there, `echarts.setOption` which re-draws the chart. Drawing is
expensive because ECharts needs to measure the DOM a lot (to calculate
overlap between labels) and because it might be calling a bunch of
`requestAnimationFrame` to run animations from ZRender.
<img width="1173" height="384" alt="Screenshot 2025-11-14 at 11 20
53 AM"
src="https://github.com/user-attachments/assets/b907b040-e8b0-47e2-85aa-9b97af9aa15f"
/>
This PR makes two major changes:
1. Turn animations off completely on Dashboards charts. We don't have
any animations configured, but even still ZRender will call
`requestAnimationFrame` to schedule animations sometimes. Not a major
win, but still a win
2. Allow ECharts to merge chart options. In ECharts, calling
`setOption`, by default, will compare the objects and only update and
re-draw things that changed. This is _much_ more efficient than
re-drawing (see above). In `BaseChart`, we've set `notMerge` to `true`
by default, which forces ECharts to re-draw! I've set `notMerge` to
`false` for Dashboards, so ECharts will merge the options
There's no "After" profile, because that section disappears completely.
TADA, a huge amount of work gone.
I'm not comfortable turning off `notMerge` for all charts because in
some cases it _might_ cause UI problems, but in Dashboards this seems to
work well. I thought for a long time about doing some hardcore memoizing
of the props to ECharts, but that's too brittle and annoying, and there
are too many contexts that cause hard to avoid re-renders.1 parent a358900 commit 47ba7ab
File tree
3 files changed
+17
-2
lines changed- static/app
- components/charts
- views/dashboards/widgetCard
3 files changed
+17
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
332 | 336 | | |
333 | 337 | | |
334 | 338 | | |
| 339 | + | |
335 | 340 | | |
336 | 341 | | |
337 | 342 | | |
| |||
564 | 569 | | |
565 | 570 | | |
566 | 571 | | |
| 572 | + | |
567 | 573 | | |
568 | 574 | | |
569 | 575 | | |
| |||
580 | 586 | | |
581 | 587 | | |
582 | 588 | | |
| 589 | + | |
583 | 590 | | |
584 | 591 | | |
585 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
306 | 308 | | |
307 | 309 | | |
308 | 310 | | |
| |||
661 | 663 | | |
662 | 664 | | |
663 | 665 | | |
664 | | - | |
| 666 | + | |
665 | 667 | | |
666 | 668 | | |
667 | 669 | | |
| |||
0 commit comments