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

Gradle under the microscope

Gradle under the microscope

Talk by Aurimas Liutikas (Google) at Droidcon SF 2023

Aurimas Liutikas

July 20, 2023
Tweet

More Decks by Aurimas Liutikas

Other Decks in Programming

Transcript

  1. Who’s Aurimas? 11 years at Google 7.5 years on AndroidX

    Work closely with Android Studio, Gradle, and Jetbrains
  2. Gradle Enterprise Helpful for experiments, debugging, monitoring Free version --scan

    ge.androidx.dev OSS instance Pricing not transparent, closed source
  3. Configuration Caching (CC) Serializing task graph into disk, I/O instead

    of recalculating org.gradle.configuration-cache=true orders of magnitude faster Stable with Gradle 8.1 (works in 8.0 too)
  4. Why Invest In Configuration Optimization? CC is not portable, container

    based CI always runs it Once execution is great, configuration phase can become >50% of time Bottleneck for Studio Gradle Sync, never uses CC
  5. Why run with configuration cache in CI Matching dev flow

    Catch bugs in build logic, plugins Up to date task validation savings
  6. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies
  7. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies every build.gradle :
  8. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies every build.gradle : :a :b
  9. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies every build.gradle : :a :b :a:a1 :a:a2
  10. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies every build.gradle : :a :b :a:a1 :a:a2 … :a:a1:aa1
  11. Stages of Gradle Configuration settings.gradle Settings plugins Remote Cache Initialization

    Parsing version catalogs buildSrc (~ included build) settings.gradle build buildSrc/build.gradle and dependencies every build.gradle : :a :b :a:a1 :a:a2 … :a:a1:aa1 CC serialization single threaded walk through projects serializing tasks includes serializing all configurations (can be really slow)
  12. Basic optimizations Tasks register vs create Load all plugins, apply

    when needed Write your own instead of loading giant plugins org.gradle.configureondemand=true (potentially a foot gun)
  13. Creating a scenario to optimize rerunDryRun { tasks = ["bOS"]

    gradle-args = ["--dry-run", "--rerun-tasks"] daemon = cold warm-ups = 1 clear-configuration-cache-state-before = BUILD }
  14. Where Do I Look First? Your own build logic first

    More familiar, easier to fix Look for chunks >100ms
  15. Solution: remove or no-op when not needed In androidx it

    was to replace it with NoOpGitClient for local builds
  16. Be careful with I/O Avoid if you can Use BufferedInputStream

    if you cannot https://github.com/gradle/gradle/pull/24105
  17. “Dripping water hollows out stone” - Ovid If everyone in

    the audience today went and removed wasted 50ms… The more core the plugin, greater the impact