Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to reduce Android app launch time by scoping your dependencies using Koin DI

How to reduce Android app launch time by scoping your dependencies using Koin DI

Aldo Kelvianto Wachyudi
LINE Indonesia Android Engineer
https://linedevday.linecorp.com/jp/2019/sessions/S2-3

LINE DevDay 2019

November 21, 2019
Tweet

More Decks by LINE DevDay 2019

Other Decks in Technology

Transcript

  1. 2019 DevDay
    How To Reduce Android App
    Launch Time by Scoping Your
    Dependencies Using Koin DI
    > Aldo Kelvianto Wachyudi
    > LINE Indonesia Android Engineer

    View full-size slide

  2. Introduction
    > I've been working on LINE Today App project since 2018
    > LINE Today App version is now v4.1
    > LINE Today features: Read news, watch videos, listen to podcast, give
    comments
    > How do we maintain more features in the future?

    View full-size slide

  3. More
    Features
    More
    Objects
    More
    Modules

    View full-size slide

  4. Dev Day Schedule App
    List of Speakers
    Show News

    View full-size slide

  5. > SpeakerActivity
    > SpeakerModule // 7 objects
    List of Speaker
    News
    > NewsActivity
    > NewsModule // 6 objects
    Features, Activity, Module

    View full-size slide

  6. How To Inject These Modules?

    View full-size slide

  7. What's the Problem?
    > Production app has more than 2 modules and 15 objects
    > If we have 200 objects, it takes ~> 16.7 ms (skipped frame!)
    > Those objects linger in memories, used or not
    > Not ready to scale
    > Hard to maintain the code. Minor changes cause unexpected side-effect

    View full-size slide

  8. How To Improve This?
    > SpeakerActivity don't need NewsActivity objects, vice versa
    > Scope the objects
    "Scope is a fixed duration of time or
    method calls in which an object exists."

    View full-size slide

  9. Injection Result - Unscoped
    // 2 objects from context
    // 7 objects from speaker module
    // 6 objects from news module
    total 15 registered definitions
    load modules in 1.717 milliseconds

    View full-size slide

  10. Injection Result - Scoped
    // 73% faster!
    // Only binds 2 objects (Application and Context)
    total 15 registered definitions
    load modules in 0.448 milliseconds

    View full-size slide

  11. Scoping Benefit
    > Faster app launch time
    > The objects exist only when they're used
    > Ready to scale
    > More maintainable code

    View full-size slide

  12. How To Scope Module?
    Unscoped

    View full-size slide

  13. How To Scope Module?
    Scoped

    View full-size slide

  14. Summary
    > In Koin, Scope can ties to Activity, Fragment, ViewModel, or custom (define
    yourself)
    > It’s a concept, can be applied to any DI framework
    > In Dagger, you can use Scope annotation or Subcomponents
    > Code is available on https://github.com/aldoKelvianto/KoinScopeDemo

    View full-size slide