5

Playing around with new Canvas/TimelineView for iOS 15. I tried to create a particle system using the official WWDC tutorial, but couldn't manage to fix performance-related issues.

Here is the code:

struct MyView: View {
    @State private var count = 32*32
    var body: some View {
        TimelineView(.animation) { timeline in
            Canvas { context, size in
                let now = timeline.date.timeIntervalSinceReferenceDate
                for i in 0..<count {
                    context.fill(Ellipse().path(in: CGRect(x: size.width*0.01*Double(i), y: size.height*0.01*Double(i), width: 20.0, height: 20.0)), with: .color(.green))
                }

            }
        }
    }
}

It just draws 1024 circles but already consumes about 20% of the Simulator CPU and 50% of my iPhone 8 CPU. Considering the power of the iPhone and said effectiveness of new frameworks, is it expected behavior? How should I fix this if I need much more than 1024 circles?

Hekes Pekes
  • 1,175
  • 2
  • 12
  • 28

0 Answers0