Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load optimization (iphone) #292

Open
InfiniteFalltrough opened this issue Feb 20, 2024 · 4 comments
Open

load optimization (iphone) #292

InfiniteFalltrough opened this issue Feb 20, 2024 · 4 comments

Comments

@InfiniteFalltrough
Copy link

InfiniteFalltrough commented Feb 20, 2024

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)

@HayesGordon
Copy link
Contributor

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?

@InfiniteFalltrough
Copy link
Author

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:

Screen.Recording.2024-02-27.at.11.51.41.AM.mov

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: 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!

@taydr
Copy link

taydr commented Mar 21, 2024

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)
    })

@InfiniteFalltrough
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants