LottieFiles / dotlottie-ios

.lottie player for iOS
MIT License
40 stars 6 forks source link

[Memory consuming] In UIKit, DotLottieAnimation uses too much memory despite its smaller size compared to json #33

Open lgvv opened 3 weeks ago

lgvv commented 3 weeks ago

Description of the issue

The .lottie file has a smaller file size, but it uses significantly more memory in a UIKit environment compared to the .json file.

not used

스크린샷 2024-08-23 오전 11 09 31

.lottie

.json

스크린샷 2024-08-22 오후 5 30 57

Summary

It seems to be about a 10-fold difference.

Sample Code

class LottieExampleViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

//        typeJson() // use memory about 2MB
//        typeLottie() // use memory about 20MB
    }

    func typeJson() {
        let typeJson = LottieAnimationView(name: "json_type")
        view.addSubview(typeJson)
        typeJson.backgroundColor = .orange.withAlphaComponent(0.2)
        typeJson.snp.makeConstraints {
            $0.top.leading.trailing.equalToSuperview()
            $0.bottom.equalTo(view.snp.centerY)
        }
        typeJson.loopMode = .loop
        typeJson.play()
    }

    func typeLottie() {
        let typeLottie = DotLottieAnimation(fileName: "lottie_type", config: .init(useFrameInterpolation: false))
        let v: UIView = typeLottie.view()
        view.addSubview(v)
        v.backgroundColor = .green.withAlphaComponent(0.2)
        v.snp.makeConstraints {
            $0.top.equalTo(view.snp.centerY)
            $0.leading.trailing.bottom.equalToSuperview()
        }
        typeLottie.setLoop(loop: true)
        typeLottie.play()
    }
}

Linked issues

theashraf commented 3 weeks ago

@samuelOsborne In the core dotlottie-rs player, we're currently storing both the dotLottie file buffer and the deflated Lottie JSONs in memory, which leads to double the memory consumption. a possible solution would be to check if the dotLottie file contains only a single animation. If so, we can extract and keep that single animation in memory, allowing us to remove the dotLottie file from local memory.