3

I am displaying multiple charts in a view.
The charts are just paths in a frame and data comes from an csv file (not bigger than 400mb).
Those charts are displayed inside of a LazyVGrid and the whole view is inside a scroll view.

Loading the view takes about 10 - 20 seconds, but when I start scrolling through the charts, it becomes very laggy.
To solve this I tried to attach .drawingGroup() to the chart views, but there where nearly no performance change.

the code looks something like this:

import SwiftUI


struct GroupView: View {

@State var chartData = [CGFloat]()

  let columns = [
        GridItem(.adaptive(minimum: 720))
 
       ]
    

  var body: some View {

VStack{

 ScrollView {
                
   LazyVGrid(columns: columns){

     CSVChart(data: chartData, chartName: String, x-yaxisName: [String](), lineColor: CGColor)
        .frame(width: 700, height: 300, alignment: .center)
        .drawingGroup() // there is as well no performance change when .drawingGroup()  is inside the chart view

        }

     
    }

}.onAppear{
   
 chartData = // get csv data logic

   }



}
}



I know that the csv file is quite large, and that this will cause the slow behaviour, but I thought that other apps aren't that laggy when working with large files so this might be fixable.
It would be great if someone could help me with this problem.

DoTryCatch
  • 1,052
  • 6
  • 17
  • In my experience SwiftUI is just not ready for the real world and immediately falters when tasked with something harder than displaying a table view. I'd try implementing it with Cocoa (or UIKit). – idmean Jan 19 '21 at 21:35
  • Hey, were you able to solve this issue? I am having the same situation. https://stackoverflow.com/questions/68501790/swiftui-cpu-high-usage-on-real-time-foreach-view-updating-macos – arata Jul 23 '21 at 16:05
  • @arata No, unfortunately not. Still looking for some good solution. – DoTryCatch Jul 25 '21 at 12:04

1 Answers1

0

Add the axis to your ScrollView to tell on which side it can grow.

ScrollView(.vertical) {
Michel Donais
  • 474
  • 4
  • 13
  • thanks for the hint, but it is still very laggy. I will now just create a data disk stream, to avoid buffering all the data in memory and just display vector graphics. – DoTryCatch Feb 15 '21 at 17:44