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

Improve the build times of your project is not impossible. How we achieved it in N26.

antonicg
September 26, 2023

Improve the build times of your project is not impossible. How we achieved it in N26.

In 2021/2022 N26 android platform team focused on reducing the build times of the project. We achieved to reduce them a 75%! This talk is about how we achieve that successful result that made the N26 Android Engineers happy and more productive.

I will present the implementations that N26 platform team did to reduce the compilation time of our app module from 20-25minuts to 5-6minuts. Also we reduced the compilation time of the library modules to improve the productivity of the engineers. I will talk about the gradle dependency graph, DI (Anvil plugin from square) and about the Dependency Inversion Principle.

antonicg

September 26, 2023
Tweet

Other Decks in Programming

Transcript

  1. Antoni Castejón Improve the build times of your project is

    not impossible. How we achieved it in N26
  2. core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib core_lib core_lib core_lib core_lib core_lib single_feature_app 1 feature_app feature_lib single_feature_app 2 feature_app feature_lib single_feature_app 3 feature_app feature_lib single_feature_app 4 feature_app feature_lib The N26 android project Setup before the initiative app core libraries folder features folder
  3. single_feature_app 1 feature_app feature_lib The N26 android project Single feature

    apps • The feature code • Runs independently • Entry point • Less dependencies • Less build time
  4. feature_app The N26 android project Single feature apps • Login

    • Activity entry point • No production code • com.android.application
  5. feature_lib The N26 android project Single feature apps • Feature

    code • Production code • com.android.library
  6. The N26 android project Overview before the initiative • 312

    total modules • 119 core libraries • 70 SFAs
  7. Chat GPT 3.5 A visual representation of the dependencies between

    different components in a Gradle-based project. It refers to the relationships between different modules, libraries, and other dependencies that make up a gradle application. The Gradle dependency graph
  8. Wikipedia - Glossary of graph theory (https://en.wikipedia.org/wiki/Glossary_of_graph_theory#height) The height of

    a node in a rooted tree is the number of edges in a longest path, going away from the root, that starts at that node and ends at a leaf.
  9. About Gradle Executing a gradle task… Current execution Previous execution

    Skips execution! Gradle incremental builds and caching Outputs Outputs
  10. About Gradle But… Current execution Previous execution Reexecution is needed

    for those tasks Gradle incremental builds and caching Reexecution is NOT only needed for those tasks…
  11. About Gradle Gradle incremental builds and caching Reexecution is NOT

    only needed for those tasks… … but also for the tasks that depend on them
  12. Apply dependency inversion Solution proposed for the hypothesis • High-level

    modules should depend on abstractions rather than in low-level modules. • Abstractions should not depend on details. Details should depend on abstractions. SOLID D
  13. Apply dependency inversion Solution proposed for the hypothesis public interface

    NetworkApi { fun connectToInternet() fun disconnectFromInternet() } Abstraction public class Network : NetworkApi { override fun connectToInternet() { // Starting connection... } override fun disconnectFromInternet() { // Disconnecting... } } Details
  14. Apply dependency inversion Solution proposed for the hypothesis High-level modules

    should depend on abstractions rather than low- level modules. feature_lib details feature_lib abstraction
  15. Apply dependency inversion Solution proposed for the hypothesis Abstractions should

    not depend on details. Details should depend on abstractions. feature_lib abstraction details feature_lib abstraction details
  16. public class Network : NetworkApi { override fun connectToInternet() {

    // Starting connection... } override fun disconnectFromInternet() { // Disconnecting... } } public interface NetworkApi { fun connectToInternet() fun disconnectFromInternet() } Apply dependency inversion Solution proposed for the hypothesis abstraction details api core
  17. Apply dependency inversion Solution proposed for the hypothesis core_lib core_lib

    core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib single_feature_app 1 feature_app feature_lib single_feature_app 2 feature_app feature_lib single_feature_app 3 feature_app feature_lib single_feature_app 4 feature_app feature_lib app core libraries folder features folder core_lib
  18. feature_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib Before dependency inversion app feature_app feature_lib core_lib lib core_lib core_lib 😭
  19. feature_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib Before dependency inversion core_lib 🔄 🔄 🔄 🔄 🔄 🔄 SEQUENTIALLY
  20. With dependency inversion app feature_app feature_lib core_lib lib core_lib api

    api api api legacy app feature_app feature_lib core core 😃
  21. With dependency inversion app feature_app feature_lib core_lib lib core_lib api

    api api api legacy app feature_app feature_lib core core 🔄
  22. Process we follow Iterative Discovery Pick the top 5 core

    libraries with: ✅ More edges ✅ Easy to apply Implementation Apply DI Benchmark Compare results: master changes
  23. Chat GPT 3.5 Monolith: A monolith refers to an application

    that is built as a single, unified unit. All components and features of the application are tightly integrated into a single codebase, often resulting in a large and complex code structure. Legacy monoliths
  24. Chat GPT 3.5 Legacy: Refers to older software systems that

    are still in use but are no longer actively developed or maintained. These systems are usually built using older technologies, frameworks, and practices that might not align with modern software development trends and best practices. Legacy systems can pose challenges in terms of scalability, maintenance, and integration with newer technologies. Legacy monoliths
  25. Anvil VS Hilt Anvil • Kotlin compiler plugin • Needs

    Dagger • Merges components and modules using annotations • Doesn’t need Kapt Hilt • Dependency injection framework • Independent library • Simpli fi es Dagger DI for Android • Needs Kapt *
  26. Anvil VS Hilt Anvil • Kotlin compiler plugin • Needs

    Dagger • Merges components and modules using annotations • Doesn’t need Kapt * ✅ Without @Component ✅ Pure Kotlin
  27. core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib core_lib injectLegacy injectLegacy BaseComponent BaseSessionComponent feature_lib core_lib Legacy monoliths app
  28. app Legacy monoliths injectLegacy core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib core_lib core_lib core_lib core_lib core_lib injectLegacy BaseComponent BaseSessionComponent feature_lib core_lib ✅ Removed injectLegacy dependency ✅ Add Anvil plugin (if necessary) Done by Platform team 1 ✅ Adds Anvil Plugin ✅ Removed injectLegacy dependency Done by Product teams 2
  29. Involving product teams 1. Step by step guide 2. Tracked

    the process 3. Capacity of the teams 4. Explained the bene fi ts Explained the bene fi ts
  30. Involving product teams Explained the bene fi ts ✅ Height

    of the SFA ✅ Skip Kapt The build time of their SFA library will be reduced :
  31. Involving product teams Explained the bene fi ts ✅ Height

    of the SFA ✅ Skip Kapt The build time of the app will be ALSO reduced :
  32. core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib core_lib

    core_lib core_lib injectLegacy BaseComponent BaseSessionComponent feature_lib core_lib Legacy monoliths injectLegacy ✅ Removed injectLegacy dependency ✅ Add Anvil plugin (if necessary) Done by Platform team 1 ✅ Adds Anvil Plugin ✅ Removed injectLegacy dependency Done by Product teams 2 ✅ Delete injectLegacy Done by Platform team 3