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

Android Builds: Simple Recipes for faster feedb...

Android Builds: Simple Recipes for faster feedback loop

PRESENTED AT:

1. Droidcon San Francisco (https://x.com/Aida_Isay/status/1792228974694985893) 🇺🇸
2. DPE Tour Boston (https://x.com/Aida_Isay/status/1792211610481697089) 🇺🇸

DATES:

1. June 6, 2024
2. June 12, 2024

DESCRIPTION:

Diving into Android build optimizations, this talk revisits seemingly minor adjustments that hold untapped potential for speeding up your build process.

Often overlooked or underestimated, these simple tweaks can be game-changers in enhancing build efficiency. I'll share insights from my experience at Toast where basic changes led to significant improvements, reminding you to give these solutions a second glance.

Whether it's fine-tuning gradle properties, leveraging incremental builds, or optimizing resource usage, this session aims to highlight the often-skimmed solutions that might just be the key to a faster build.

This session is ideal for developers looking to improve build times and enhance productivity, demonstrating that sometimes, the most impactful optimizations are also the most accessible.

Aida Issayeva

June 06, 2024
Tweet

More Decks by Aida Issayeva

Other Decks in Programming

Transcript

  1. About me • 9 years as an Android engineer •

    Staff Software Engineer at Toast, Inc • Google Developer Expert for Android • Women Techmakers Ambassador
  2. Table of Contents 1 Why care? 2 Bottlenecks and fixes

    a locally in a project b remotely on CI 3 Recap
  3. Context: POS App 1 2 a b 3 294 modules

    110 contributors >2M lines of code 150 avg remote builds/day
  4. Why care? 1 2 a b 3 2022 H1 2023

    227% Contributors Number of remote builds 305% Avg build time in mins 51.5 73.88 44%
  5. 1 2 a b 3 Main priority is a build

    acceleration. for us
  6. 2a. Solution: Max heap size calculation 1 2 a b

    3 100% 70% JVM Memory Xmx Metaspace and other native memory Hungriest task
  7. 2a. Local bottlenecks: Gradle Workers 1 2 a b 3

    CPU Core 1 CPU Core 2 CPU Core 3 Gradle Worker 1 Gradle Worker 2 Gradle Worker 3 … OutOfMemoryError
  8. 2a. Solution: Gradle Workers Count Calculation 1 2 a b

    3 org.gradle.workers.max=8 Total CPU cores/1.5~2
  9. 2a. Local bottlenecks: Unused Dependencies 1 2 a b 3

    Dependency resolution Downloading artifacts Configuration time uncached Classpath size
  10. 2a. Local bottlenecks: Outdated Dependencies 1 2 a b 3

    Inefficient build processes Increased resolution time Compatibility issues Deprecated features
  11. 2a. Solution: Unused & Outdated Dependencies 1 2 a b

    3 Automated dependency management: Use plugins (Dependabot, etc)
  12. 2b. Remote Bottlenecks 1 2 a b 3 outdated hardware

    container configuration + plugins' settings inefficient scripts applicable locally too
  13. 2b. Solution: Hardware age 1 2 a b 3 CPU

    * More RAM * More > 10 > 32 = Optimal Performance* *Hardware
  14. 2b. Solution: Jenkins Agent Required Memory 1 2 a b

    3 (XmxSize + XmxSize*30%) + ((max.workers * XmxSize)* 30%) + ((1 + 2) * 30%) = optimal memory JVM and OS overhead Daemon 1 2 % of all workers at max heap not modularized project
  15. 2b. Remote bottlenecks: Container Settings & Config 1 2 a

    b 3 Container startup time Resource Allocation Old Instance Wait times
  16. 2b. Solution: Container Settings & Config 1 2 a b

    3 1.Allocate high number of agents 2.Keep agents warm 3.Migrate to a newer instance
  17. 2b. Remote bottlenecks: Jenkins Plugin Settings 1 2 a b

    3 Build Queue Congestion Build trigger on PR metadata change
  18. 2b. Solution: Jenkins Plugin Settings 1 2 a b 3

    1. Don't trigger a build on PR metadata change 2. Cancel ongoing builds after a new commit is pushed
  19. 2b. Remote bottlenecks: inefficient CI scripts 1 2 a b

    3 Serial execution of most stages Timeouts on different plugin responses Staggered gradle tasks
  20. 2b. Remote bottlenecks: inefficient CI scripts 1 2 a b

    3 1. Parallelize stages 2. Investigate and reduce timeouts 3. Combine logically related gradle tasks
  21. Local: - enable parallel - enable cache - optimize memory

    config - manage gradle workers 1 2 a b 3 3. Recap Remote: - upgrade hardware - optimize container settings - fine-tune plugin events - improve CI scripts
  22. 1 2 a b 3 3. Recap Before H2 2023

    After H2 2023 After Q1 2024 43% 31% 61%
  23. 1. Dependency Analysis Gradle Plugin - unused & transitive dependencies

    2. Dependabot - automated dependency updates in Github 3. RenovateBot 4. Gradle Profiler - profiling & benchmarking gradle builds 5. Gradle Process Plugin - information about gradle processes 1 2 a b 3 3. Resources: Plugins & Tools
  24. 1. Java Memory model specification 2. Introduction to Java's Memory

    model 3. Essential Tips to minimize Gradle Build Time 4. From laptops to advanced CI 5. Managing nodes in Jenkins 1 2 a b 3 3. Resources: References