rive-ios icon indicating copy to clipboard operation
rive-ios copied to clipboard

load optimization (iphone)

Open InfiniteFalltrough opened this issue 1 year ago • 4 comments

perhaps someone has already encountered the following behavior:

  • memory consumption increases by 2 times when rewinding the animation back and forth, but only to advanced level and stops (not so critical)
  • energy consumption is consistently high (sometimes even very high) (critical issue)
  • but at the same time, CPU load is ~8-11% (during playing 30-35%)

does anyone know possible ways to optimize (at least energy consumption)?

(update: Skia/Rive - doesn't matter)

InfiniteFalltrough avatar Feb 20 '24 06:02 InfiniteFalltrough

Hi @InfiniteFalltrough, thanks for reporting and sorry that you're running into this. Could you share a sample project with us that shows how you're using the SDK with the animations you're using that are showing these metrics?

HayesGordon avatar Feb 20 '24 15:02 HayesGordon

Hi @InfiniteFalltrough, thanks for reporting and sorry that you're running into this. Could you share a sample project with us that shows how you're using the SDK with the animations you're using that are showing these metrics?

sorry for the late response... metrics:

https://github.com/rive-app/rive-ios/assets/65627244/e1a50c1c-8f44-4387-89f4-c2df59491641

code:

struct ContentView: View {

@State private var model = RiveViewModel(fileName: "sample/scrub-blend.2dc5d861e4cae3df534b", stateMachineName: "State Machine 1", fit: .fitWidth, alignment: .center, artboardName: "Blend")
@State private var scrollPercentage: CGFloat = 0

var body: some View {
    PositionReadableScrollView(content: {
        VStack {
            model.view().frame(width: width, height: height)
            Rectangle().frame(height: 200).foregroundColor(.clear)
            Spacer()
        }.frame(height: height + 200)
    }, onScroll: { value in
        let scroll = (value * -1) / 4
        model.setInput("ScrollPercentage", value: scroll)
    })
}

}

struct PositionReadableScrollView<Content>: View where Content: View { let axes: Axis.Set = .vertical let content: () -> Content let onScroll: (CGFloat) -> Void

var body: some View {
    ScrollView(axes) {
        content()
            .background(
                GeometryReader { proxy in
                    let position = (
                        axes == .vertical ?
                        proxy.frame(in: .named("scrollID")).origin.y :
                        proxy.frame(in: .named("scrollID")).origin.x
                    )
                    Color.clear
                        .onChange(of: position) { position, _ in
                            onScroll(position)
                        }
                }
            )
    }
    .coordinateSpace(.named("scrollID"))
}

}

I can even share our .riv for test, but privately, not here (if needed).

Hope something can be done about it.... I'll be grateful for any response!

InfiniteFalltrough avatar Feb 27 '24 05:02 InfiniteFalltrough

do you think it's because of the onscroll calling rive more frequently? (i'm looking to do something similar)

onScroll: { value in
        let scroll = (value * -1) / 4
        model.setInput("ScrollPercentage", value: scroll)
    })

taydr avatar Mar 21 '24 04:03 taydr

do you think it's because of the onscroll calling rive more frequently? (i'm looking to do something similar)

onScroll: { value in
        let scroll = (value * -1) / 4
        model.setInput("ScrollPercentage", value: scroll)
    })

no clue, really, the documentation for the iOS part doesn't say anything useful. (there is an opinion that the entire animation is redrawn completely, and not just rewound - just guesswork)

we have a huge animation (comics) and so far we have settled on Lottie since the metrics are much better than Rive in all respects... but I hope that Rive will be able to solve this problem, since this is a new and very convenient solution for production and I would like to work with it!

InfiniteFalltrough avatar Mar 21 '24 06:03 InfiniteFalltrough