Realtime LineChart poor performance due to calcMinMax
- Dominant language
- Swift
- Stars
- 28k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I've found a possible performance bottleneck. In a realtime chart Adding many entries per second to the chart I noticed that automatically the calcMinMax of the dataset is called just after EACH `values.append(e)`
calcMinMax function determine the min and max values using .forEach that is causing the CPU over 60% spent looping the values, moreover in the main thread.
I'm performing some experiment disabling min/max calculation or using native for loop instead of array .forEach
@danielgindi please have a look, is really calcMinMax on **all** values needed? I calculate min/max Y values manually in my code and only on **visible values**, so maybe you could expose some boolean to enable/disable min/max auto calculation and improving performance removing the forEach function and avoid function calls.
```
open override func calcMinMax()
{
guard !values.isEmpty else { return }
_yMax = -Double.greatestFiniteMagnitude
_yMin = Double.greatestFiniteMagnitude
_xMax = -Double.greatestFiniteMagnitude
_xMin = Double.greatestFiniteMagnitude
values.forEach { calcMinMax(entry: $0) }
}
```
Contributor guide
Assessment
This issue has not been assessed yet.