airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.67k stars 3.74k forks source link

求助怎么修复卡顿 #2343

Closed HaoRuizhi closed 5 months ago

HaoRuizhi commented 6 months ago

Thread 0: 0 libsystemkernel.dylib 0x1de0610f4 0x1de060000 + 4340 1 libdispatch.dylib 0x19e95af4c 0x19e956000 + 20300 2 CFNetwork 0x197a395cc 0x197a35000 + 17868 3 CFNetwork 0x197af988c 0x197a35000 + 805004 4 Foundation 0x19598b9a4 0x1958f8000 + 604580 5 AppName NSData.init(contentsOf:options:) (in AppName) 96 6 AppName FilepathImageProvider.imageForAsset(asset:) (in AppName) 312 7 AppName AnimationImageProvider.imageForAsset(asset:)AnimationImageProvider (in AppName) 20 8 AppName CachedImageProvider.imageForAsset(asset:) (in AppName) 132 9 AppName AnimationImageProvider.imageForAsset(asset:)AnimationImageProvider (in AppName) 20 10 AppName ImageLayer.setupImage(context:) (in AppName) 180 11 AppName LayerModel.makeAnimationLayer(context:) (in AppName) 516 12 AppName CALayer.setupLayerHierarchy(for:context:) (in AppName) 280 13 AppName PreCompLayer.setup(context:) (in AppName) 304 14 AppName LayerModel.makeAnimationLayer(context:) (in AppName) 296 15 AppName CALayer.setupLayerHierarchy(for:context:) (in AppName) 280 16 AppName CoreAnimationLayer.setupChildLayers() (in AppName) 252 17 AppName CoreAnimationLayer.init(animation:imageProvider:textProvider:fontProvider:compatibilityTrackerMode:logger:) (in AppName) 556 18 AppName LottieAnimationView.makeAutomaticEngineLayer(for:) (in AppName) 336 19 AppName LottieAnimationView.makeAnimationLayer(usingEngine:) (in AppName) 160 20 AppName $s6Lottie0A13AnimationViewC9animation13imageProvider04textF004fontF013configuration6loggerAcA0aB0CSg_AA0b5ImageF0_pSgAA0b4TextF0_pAA0b4FontF0_pAA0A13ConfigurationVAA0A6LoggerCtcfcTf4nneennn_nAA07DefaultlF0C_AA0pmF0CTB5 (in AppName) 1004 21 AppName LottieAnimationView.__allocating_init(filePath:imageProvider:animationCache:configuration:) (in AppName) 944 以上是具体堆栈信息 卡顿点事NSData.init(contentsOf:options:) 调用是在主线程调用的,大家有遇到过这种问题不

calda commented 6 months ago

Please share a sample project that reproduces this error

github-actions[bot] commented 6 months ago

This issue is stale because it is marked "can't reproduce" and has had no activity in the past week. Please comment with additional information, or this issue will be closed due to inactivity in one week.

supergithuber commented 5 months ago

Thread 0: 0 libsystemkernel.dylib 0x1de0610f4 0x1de060000 + 4340 1 libdispatch.dylib 0x19e95af4c 0x19e956000 + 20300 2 CFNetwork 0x197a395cc 0x197a35000 + 17868 3 CFNetwork 0x197af988c 0x197a35000 + 805004 4 Foundation 0x19598b9a4 0x1958f8000 + 604580 5 AppName NSData.init(contentsOf:options:) (in AppName) 96 6 AppName FilepathImageProvider.imageForAsset(asset:) (in AppName) 312 7 AppName AnimationImageProvider.imageForAsset(asset:)AnimationImageProvider (in AppName) 20 8 AppName CachedImageProvider.imageForAsset(asset:) (in AppName) 132 9 AppName AnimationImageProvider.imageForAsset(asset:)AnimationImageProvider (in AppName) 20 10 AppName ImageLayer.setupImage(context:) (in AppName) 180 11 AppName LayerModel.makeAnimationLayer(context:) (in AppName) 516 12 AppName CALayer.setupLayerHierarchy(for:context:) (in AppName) 280 13 AppName PreCompLayer.setup(context:) (in AppName) 304 14 AppName LayerModel.makeAnimationLayer(context:) (in AppName) 296 15 AppName CALayer.setupLayerHierarchy(for:context:) (in AppName) 280 16 AppName CoreAnimationLayer.setupChildLayers() (in AppName) 252 17 AppName CoreAnimationLayer.init(animation:imageProvider:textProvider:fontProvider:compatibilityTrackerMode:logger:) (in AppName) 556 18 AppName LottieAnimationView.makeAutomaticEngineLayer(for:) (in AppName) 336 19 AppName LottieAnimationView.makeAnimationLayer(usingEngine:) (in AppName) 160 20 AppName $s6Lottie0A13AnimationViewC9animation13imageProvider04textF004fontF013configuration6loggerAcA0aB0CSg_AA0b5ImageF0_pSgAA0b4TextF0_pAA0b4FontF0_pAA0A13ConfigurationVAA0A6LoggerCtcfcTf4nneennn_nAA07DefaultlF0C_AA0pmF0CTB5 (in AppName) 1004 21 AppName LottieAnimationView.__allocating_init(filePath:imageProvider:animationCache:configuration:) (in AppName) 944 以上是具体堆栈信息 卡顿点事NSData.init(contentsOf:options:) 调用是在主线程调用的,大家有遇到过这种问题不

same issue as you

supergithuber commented 5 months ago

Please share a sample project that reproduces this error

to_keyboard.json

When loading the lottie's JSON above, it will block the main thread of app more than ten seconds.

sample code: let view = LottieAnimationView(name: "to_keyboard") view.play()

calda commented 5 months ago

I tested this locally and I see that the performance issue happens in a debug build, but not in a release build.

That suggests this is some sort of pathological performance issue in the Swift compiler (e.g. the compiler not generating properly optimized code in debug, or something) rather than a problem in Lottie itself.

If you have repro steps for this that show performances issues in a release build as well, feel free to re-open the issue.

liuyongjiesail commented 2 weeks ago

LottieView.init { .named("cleanup_complete") } placeholder: { ProgressView() } .playing()

SwiftUI 使用异步加载方式可以解决同步加载大文件导致的卡顿问题