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

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

Open
lgvv opened this issue Aug 22, 2024 · 1 comment

Comments

@lgvv
Copy link
Contributor

lgvv commented Aug 22, 2024

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

  • filesize: 2KB
스크린샷 2024-08-22 오후 5 30 37

.json

  • filesize: 7KB
스크린샷 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
Copy link
Member

@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.

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

No branches or pull requests

2 participants