alexzhirkevich / compottie

Compose Multiplatform library for rendering Lottie animations with standalone pure Kotlin renderer
MIT License
249 stars 9 forks source link

[Bug]: iOS App hangs very frequently when using Compottie #15

Open Vaibhav2002 opened 3 months ago

Vaibhav2002 commented 3 months ago

What happened?

iOS App hangs very frequently when scrolling lists, swiping pager, selecting bottom nav items if there are lottie animations in the UI Like in every 2-3min while just scrolling a vertical lazy list or switching pager, iOS App completely hangs and user has to close the app and re-open it

Reason why I feel its due to Compottie

I replaced every lottie animation in app with a blank Box composable and even after hours of scrolling, swiping pages, doing all kind of interactions, app did not hang at all

Tested this for 2 days, and there has not been a single hang While as soon as i uncomment the Compottie code, the frequent app hangs starts again

This is degrading User Experience a lot.

This is only happening on iOS, Android works pretty good with no such hangs

Composable code

@Composable
fun Lottie(
    animationPath: String,
    modifier: Modifier = Modifier,
    isPlaying: Boolean = true,
    isInfinite: Boolean = true,
    contentScale: ContentScale = ContentScale.Fit,
    speed: Float = 1f,
    dynamicProperties: LottieDynamicProperties? = null,
    onComplete: (() -> Unit)? = null,
) {
    val composition by rememberLottieComposition {
        LottieCompositionSpec.JsonString(Res.readBytes(animationPath).decodeToString())
    }

    val progress by animateLottieCompositionAsState(composition)

    LaunchedEffect(progress) {
        if (progress == 1f) onComplete?.invoke()
    }

    val painter = rememberLottiePainter(
        composition = composition,
        isPlaying = isPlaying,
        iterations = if (isInfinite) Compottie.IterateForever else 1,
        speed = speed,
        dynamicProperties = dynamicProperties
    )

    Image(
        painter = painter,
        modifier = modifier,
        contentDescription = null,
        contentScale = contentScale
    )
}

Unsupported features

What Compottie version do you experience the bug on?

2.0.0-beta02

What platforms are you seeing the problem on?

iOS

Does Compottie log anythyng to the stdout / your logger set with Compottie.logger?

No
alexzhirkevich commented 3 months ago

Any animation example / xcode profiling info? What is causing the ANR? Memory? Cpu? Do you have multiple animations from the same json file on screen at the same time? Have you tested the release build? Can you try the sample app? There is also a lazy grid of various animations and nothing hangs for me

alexzhirkevich commented 3 months ago

Android works pretty good with no such hangs

The code is 99% shared so it can be a Compose issue

Vaibhav2002 commented 3 months ago

Yes, i have multiple animations from same json running in the same screen Some lazy column items have the same animation

This is only happening in release build, I never encountered this when running app on debug builds or in simulator I am using this on production, and its hanging in a lot of devices

Few animations which i am using:

alexzhirkevich commented 3 months ago

Try to disable composition cache with rememberLottieComposition(key = null)

alexzhirkevich commented 3 months ago

It's hard to tell anything concrete without a reproducer. Are there specific devices it hangs on? Old low-memory iphones? Is you app open source?

Vaibhav2002 commented 3 months ago

Making a reproducer is difficult, as it just happens even with a simple lazy column It hangs even on latest iPhone 15, 14 devices

App is not open source.

The composable i shared above, is how i use it everywhere.

I'll try with disabling composition cache and update here

Vaibhav2002 commented 3 months ago

@alexzhirkevich It still crashes Even after disabling composition cache

Vaibhav2002 commented 3 months ago

I managed to get some Crash logs, maybe that might help Medial-2024-08-05-171516.txt Medial-2024-08-05-171238.txt Medial-2024-08-05-171430.txt

LaatonWalaBhoot commented 3 months ago

@alexzhirkevich Any update on this? Facing the same issue

alexzhirkevich commented 3 months ago

Do you have a reproducer?

LaatonWalaBhoot commented 3 months ago

Its completely random. I am using it as in the Read me

alexzhirkevich commented 3 months ago

Any relevant stacktrace? Profiling info? Memory dump?

LaatonWalaBhoot commented 3 months ago

It's the same crash logs as @Vaibhav2002

alexzhirkevich commented 3 months ago

This logs only says that the app was terminated due to exceeding the backround work quota. What compose and kotlin version do you use?

LaatonWalaBhoot commented 3 months ago

Compose 1.6.11 Kotlin 2.0.0

alexzhirkevich commented 3 months ago

Any special usages? Maybe this happen when you use lotties with images or with dynamic properties?

LaatonWalaBhoot commented 3 months ago

Yes dynamic properties are used for light and dark switch Yes we use lottie with images but it works fine in Android Also the animation is in cells of lazy column

alexzhirkevich commented 3 months ago

Can you try it without dynamic properties and then without images? It will help to find the root cause

alexzhirkevich commented 2 months ago

May be improved in 2.0.0-rc01

LaatonWalaBhoot commented 2 months ago

@alexzhirkevich What was the cause? Sorry we had to revert since on production iOS users were reporting a lot of crashes

alexzhirkevich commented 2 months ago

There just was some refactoring in terms of synchronisation and simultaneous composition running. I can't be sure it is fixed completely since there is no reproducer. You can try it in non-prod env

sahilbajaj commented 2 weeks ago

@Vaibhav2002 @LaatonWalaBhoot Is the issue fixed for you on iOS with latest versions?

LaatonWalaBhoot commented 2 weeks ago

@sahilbajaj Seems like the issues have subsided for now. But unfortunately this observation is purely anecdotal Would need some more time to be more objective

sahilbajaj commented 2 weeks ago

Thanks @LaatonWalaBhoot

vickyleu commented 1 week ago

@alexzhirkevich I just experienced a crash here as well. Repeatedly displaying and then closing the Lottie animation causes a crash. The crash occurs in the class io/github/alexzhirkevich/compottie/internal/shapes/TransformShape.kt. Could this issue be due to deep copying? TransformShape.kt Line 86

Crash Details:

SIGSEGV

SEGV_ACCERR

0   libobjc.A.dylib                     _objc_release_x8 + 16
5   AVFCore                             0x00000001b3c04000 + 43256
6   优课UOOC                              __cxa_throw + 23215540
7   优课UOOC                              __cxa_throw + 23312100
8   优课UOOC                              __cxa_throw + 8076556
9   优课UOOC                              __cxa_throw + 8065980
10  优课UOOC                              __cxa_throw + 9556604
11  优课UOOC                              __cxa_throw + 9699200
12  优课UOOC                              __cxa_throw + 57555400
13  libdispatch.dylib                    __dispatch_call_block_and_release + 32
23  UIKitCore                            _block_destroy_helper.23 + 10212
24  优课UOOC                              0x00000001024a4000 + 33648
25  dyld                                 0x00000001c7855000 + 212276

Address Calculation:

python3 -c "print(hex(0x00000001024a4000 + 33648))"
# Result: 0x1024ac370

Symbolicated Output:

vickyleu@vickydeMac-mini dSYMs % atos -o "优课UOOC.app.dSYM/Contents/Resources/DWARF/优课UOOC" -arch arm64 0x1024ac370
# Result: kfun:io.github.alexzhirkevich.compottie.internal.shapes.annotationImpl$kotlinx_serialization_json_JsonClassDiscriminator$0.equals#internal.958 (in 优课UOOC) (TransformShape.kt:1)
alexzhirkevich commented 1 week ago

@vickyleu Thanks for detailed crash log. Seems like the issue is somewhere in generated serializer descriptor. Does it happen for all animations or for some specific? And does it always happen in the TransformShape? Is only the iOS version affected? Maybe you can share the animation? If you want you can mail it to me

vickyleu commented 1 week ago

We're currently using only one Lottie animation, and the crash is triggered very rarely. I clicked for an entire afternoon and it only happened once. Out of approximately 400 phased-release users, about 7 to 10, only ios, compottie rc-02

vickyleu commented 1 week ago

@alexzhirkevich I have sent the email attachment