elastic-charts icon indicating copy to clipboard operation
elastic-charts copied to clipboard

Performance: Formatter is called for each data point in bar chart even if not used

Open flash1293 opened this issue 3 years ago • 1 comments

Describe the issue In https://github.com/elastic/elastic-charts/blob/master/packages/charts/src/chart_types/xy_chart/rendering/bars.ts#L92 the provided formatter is called for each data point in the series, but it's only used in special circumstances:

https://github.com/elastic/elastic-charts/blob/master/packages/charts/src/chart_types/xy_chart/rendering/bars.ts#L96

In case of charts with lots of series and slow formatting functions provided this can have a noticable performance impact.

E.g. in the following chart it's spending 44ms in getConvertedValue (out of ~360ms total blocking rendering time): Screenshot 2022-02-10 at 12 36 32

Screenshot 2022-02-10 at 12 43 04

To Reproduce Configure a bar chart without labels on the bars and observe the provided formatter being called.

Expected behaviour Formatter should only be called if necessary to render the chart correctly

flash1293 avatar Feb 10 '22 11:02 flash1293

Thanks Joe, yep, this can definitely be improved a lot We can probably also call the value formatting only when showing the tooltip, without having a precomputed value saved

markov00 avatar Feb 10 '22 12:02 markov00