Share
From Laptop Builds to Advancedย CI
How do you transition from the solo-coder mindset to building a robust, automated CI pipeline that supercharges your team?
Once you get a basic pipeline running there are numerous aspects to evaluate:
* Are the results useful?
* You start to add unit test results and collect build artifacts. Is it fast and reliable enough that the team benefits from it?
* Do you need a merge queue or do you need better checks?
* What is consistently missed that you can automate?
* What tedious repetitive tasks can you transform into a welcome resource?
* Are you hitting resource limits that require an engineering investment to mitigate?
* What JVM options are right for your codebase?
* Is Docker useful? How far should you go in your optimizations?
* How do you secure the pipeline?
We'll delve into each topic and share how to apply our learnings to empower you. Along the way we will discuss how to approach stakeholders outside engineering to demonstrate the value it brings to a business. Join us for a saga of struggles and victories and how we transformed our CI pipeline at a modern scale-up business.
Jason Pearson
Transcript
281 slides
-
From Laptop Builds to Advanced CI Oct 27th, 2023 Jason
Pearsonโจ Senior Staff Engineer Formerly Hinge -
CI experience since 2011. Built Android at Hinge, went from
solo dev to 24 Android engineers. Also spent years in backend and fullstack roles across various companies. -
Make it Faster 12 9 6 3 0 Unit Tests
Release R8 UI Tests Unit Tests Release R8 UI tests minutes -
~400 Modules ๐ป 290k lines of Kotlin 24 active contributors
Context Dagger Hilt (KAPT) ๐ก Gradle Kotlin Scripts KSP (except Dagger) -
Problems ๐คฏ Distracting from Feature Work โ Regressions ๐ดโ Security
Concerns CI Solutions ๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests ๐ Automate Security -
When do we build? What do we run? Self hosted
or Managed? What should CI look like? -
What should CI look like? This talk will focus on
builds on commit push -
version: 2.1 jobs: unit_tests: docker: - image: circleci/android:api-34-node steps: -
checkout config.yml ๐ง -
version: 2.1 jobs: unit_tests: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew testDebugUnitTest config.yml ๐ง -
* What went wrong: Execution failed for task ':features:user-account:fresh- start:testInternalDebugUnitTest'.
> There were failing tests. See the report at: file:///mnt/ramdisk/ features/user-account/fresh-start/build/reports/tests/ testInternalDebugUnitTest/index.html * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':features:user-account:fresh-start:testInternalDebugUnitTest'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$e xecuteIfValid$1(ExecuteActionsTaskExecuter.java:148) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeI fValid(ExecuteActionsTaskExecuter.java:146) at ๐ง -
* What went wrong: Execution failed for task ':features:user-account:fresh- start:testInternalDebugUnitTest'.
> There were failing tests. See the report at: file:///mnt/ramdisk/ features/user-account/fresh-start/build/reports/tests/ testInternalDebugUnitTest/index.html * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':features:user-account:fresh-start:testInternalDebugUnitTest'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$e xecuteIfValid$1(ExecuteActionsTaskExecuter.java:148) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeI fValid(ExecuteActionsTaskExecuter.java:146) at ๐ง -
* What went wrong: Execution failed for task ':features:user-account:fresh- start:testInternalDebugUnitTest'.
> There were failing tests. See the report at: file:///mnt/ramdisk/ features/user-account/fresh-start/build/reports/tests/ testInternalDebugUnitTest/index.html * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':features:user-account:fresh-start:testInternalDebugUnitTest'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$e xecuteIfValid$1(ExecuteActionsTaskExecuter.java:148) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeI fValid(ExecuteActionsTaskExecuter.java:146) at ๐ง -
version: 2.1 jobs: unit_tests: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew testDebugUnitTest config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f \ -regex โ.*/build/test-results/.*xml when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f \ -regex โ.*/build/test-results/.*xmlโ \โจ -exec cp {} when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f \ -regex โ.*/build/test-results/.*xmlโ \โจ -exec cp {} ~/test-results/junit/ \; when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f \ -regex โ.*/build/test-results/.*xmlโ \โจ -exec cp {} ~/test-results/junit/ \; when: always - store_test_results: path: ~/test-results config.yml ๐ง -
unit_tests: docker: - image: circleci/android:api-34-node steps: - checkout - run:
./gradlew testDebugUnitTest - run: name: Save Test Results command: | mkdir -p ~/test-results/junit/ find . \ -type f \ -regex โ.*/build/test-results/.*xmlโ \โจ -exec cp {} ~/test-results/junit/ \; when: always - store_test_results: path: ~/test-results config.yml โ -
version: 2.1 jobs: ui_tests: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew connectedDebugAndroidTest config.yml โ ๐ง -
version: 2.1 jobs: ui_tests: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew connectedDebugAndroidTest config.yml โ โ ๐ง -
But how should we automate UI tests? Donโt write them
to begin with -
But how should we automate UI tests? Donโt write them
to begin with OR -
But how should we automate UI tests? Donโt write them
to begin with Use a fast vendor OR -
แ BikeShed > ./gradlew tasks > Task :tasks ------------------------------------------------------------ Tasks
runnable from root project 'BikeShed' ------------------------------------------------------------ Android tasks ------------- androidDependencies - Displays the Android dependencies of the project. signingReport - Displays the signing info for the base and test modules sourceSets - Prints out all the source sets defined in this project. Build tasks ----------- assemble - Assemble main outputs for all the variants. assembleAndroidTest - Assembles all the Test applications. build - Assembles and tests this project. buildDependents - Assembles and tests this project and all projects that depend on it. buildKotlinToolingMetadata - Build metadata json file containing information about the used Kotlin tooling buildNeeded - Assembles and tests this project and all projects it depends on. -
Android tasks ------------- androidDependencies - Displays the Android dependencies of
the project. signingReport - Displays the signing info for the base and test modules sourceSets - Prints out all the source sets defined in this project. Build tasks ----------- assemble - Assemble main outputs for all the variants. assembleAndroidTest - Assembles all the Test applications. build - Assembles and tests this project. buildDependents - Assembles and tests this project and all projects that depend on it. buildKotlinToolingMetadata - Build metadata json file containing information about the used Kotlin tooling buildNeeded - Assembles and tests this project and all projects it depends on. bundle - Assemble bundles for all the variants. clean - Deletes the build directory. compileDebugAndroidTestSources compileDebugSources compileDebugUnitTestSources compileReleaseSources compileReleaseUnitTestSources Build Setup tasks ----------------- init - Initializes a new Gradle build. wrapper - Generates Gradle wrapper files. -
Android tasks ------------- androidDependencies - Displays the Android dependencies of
the project. signingReport - Displays the signing info for the base and test modules sourceSets - Prints out all the source sets defined in this project. Build tasks ----------- assemble - Assemble main outputs for all the variants. assembleAndroidTest - Assembles all the Test applications. bundle - Assemble bundles for all the variants. -
version: 2.1 jobs: build: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew assembleDebug - run: ./gradlew assembleDebugAndroidTest - run: scripts/upload_and_test.sh config.yml ๐ฉ๐ฌ -
version: 2.1 jobs: publish: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew bundleRelease config.yml -
version: 2.1 jobs: publish: docker: - image: circleci/android:api-34-node steps: -
checkout - run: ./gradlew bundleRelease - run: ./gradlew publishBundle config.yml -
version: 2.1 jobs: publish: docker: - image: circleci/android:api-34-node steps: -
checkout - run: | openssl aes-256-cbc -d \ -in bikeshed-keystore-secret \ -out ./app/bikeshed.keystore \ -k $SECRET_KEY - run: ./gradlew bundleRelease - run: ./gradlew publishBundle config.yml -
Static Analysis ktlint to ensure consistency in writing detekt for
code smells xmlstarlet to validate XML structure -
๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests ๐ Automate
Security CI Solutions -
๐ Automate Building & Publishing โBut why is it taking
so long?โ โฐ -
๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests โBut why
is it taking so long?โ โฐ -
๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests ๐ Automate
Security โBut why is it taking so long?โ โฐ -
๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests ๐ Automate
Security โBut why is it taking so long?โ โฐ -
๐ Automate Building & Publishing ๐ฉ๐ฌ Automate Tests ๐ Automate
Security โฐ ๐ฆ Caching ๐ญ Parallelization Merge Queue ๐ฅท Shadow Jobs Original Problems Scale Problems -
This is what we want 12 9 6 3 0
Unit Tests Release R8 UI Tests Unit Tests Release R8 UI tests minutes -
12 9 6 3 0 Unit Tests Release R8 UI
Tests Unit Tests Release R8 UI tests minutes How do we get to this? -
12 9 6 3 0 Unit Tests Release R8 UI
Tests Unit Tests Release R8 UI tests minutes How do we get to this? -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker ๐ฉ๐ฌ Unit Tests on CI -
๐ป Local Support Gradle Caches Build Cache ๐ป ๐ป ๐ป
Configuration Cache Dependency Cache Script Cache Local Support Local Support Local Support -
๐ป Local Support Gradle Caches Build Cache ๐ป ๐ป ๐ป
Configuration Cache Dependency Cache Script Cache Local Support Local Support Local Support -
Gradle Cache directories ~/.gradle โโโ caches โ โโโ 8.1 โ
โโโ 8.2 โ โโโ โฎ โ โโโ buildcacheโ1 โ โโโ jars-9 โ โโโ journal-1 โ โโโ modules-2 โ โโโ transforms-3 โ โโโ โฎ -
Gradle Cache directories ~/.gradle โโโ caches โ โโโ 8.1 โ
โโโ 8.2 โ โโโ โฎ โ โโโ buildcacheโ1 โ โโโ jars-9 โ โโโ journal-1 โ โโโ modules-2 โ โโโ transforms-3 โ โโโ โฎ Dependency Cache -
Gradle Cache directories ~/.gradle โโโ caches โ โโโ 8.1 โ
โโโ 8.2 โ โ โโโ generated-gradle-jars โ โ โโโ kotlin-dsl โ โโโ โฎ โ โโโ buildcacheโ1 โ โโโ jars-9 โ โโโ journal-1 โ โโโ modules-2 โ โโโ transforms-3 โ Dependency Cache Script Cache -
๐ป Local Support Gradle Caches Build Cache ๐ป ๐ป ๐ป
Configuration Cache Dependency Cache Script Cache Local Support Local Support Local Support -
Gradle Caches Build Cache ๐ป Configuration Cache Dependency Cache Script
Cache Local Support ๐ป Local Support Remote Support Remote Support -
Control Cache build dependencies 40 30 20 10 0 Partial
Cache Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change Cache build dependencies minutes cache save gradle execution gradle configuration cache restore git Docker -
# If you don't turn these on you aren't #
getting any performance wins from # Gradle Build Cache or modularization. org.gradle.caching=true org.gradle.parallel=true gradle.properties -
# Kotlin 1.7+ only # Good reason to upgrade if
you are on # an older version. kotlin.incremental.useClasspathSnapshot =true gradle.properties -
# Incremental compilation with KAPT. # Only if you still
use KAPT. kapt.incremental.apt =true gradle.properties -
# Stop generating BuildConfig Java stubs. # If this is
the last Java in your codebase # you could see a decent performance win. android.enableBuildConfigAsBytecode =true gradle.properties -
# Stop generating BuildConfig files # if you don't use
them. android.defaults.buildfeatures.buildconfig =false gradle.properties -
# Experimental flag for parallelizing # R8 work - only
useful if you have # multiple R8 tasks. android.r8.maxWorkers =2 gradle.properties -
Gradle Properties Other engineers ask me, "Where do you find
these?" github.com/androidx/androidx and other OSS projects -
Gradle Plugins & Tweaks Gradle Cache Fix Plugin Disable LiveLiterals
if you use Compose -
# Re-renables Android Cache fix plugin for currently disabled defaults
we believe are safe for a speed boost. systemProp.org.gradle.android.cache- fix.MergeSourceSetFolders.caching.enabled=true systemProp.org.gradle.android.cache- fix.ZipMergingTask.caching.enabled=true gradle.properties -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change Cache build dependencies minutes cache save gradle execution gradle configuration cache restore git Docker -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change Cache build dependencies minutes cache save gradle execution gradle configuration cache restore git Docker -
Overhead Cost ๐ฆ ๐ฆ ๐ฆ ๐ฆ Depending on how you
organize your CI jobs these costs can become significant. ๐ญ Parallelization -
Gradle Caches Build Cache ๐ป Configuration Cache Dependency Cache Script
Cache Local Support ๐ป Local Support Remote Support Remote Support -
Gradle Caches Build Cache ๐ป Configuration Cache Dependency Cache Script
Cache Local Support ๐ป Local Support Remote Support Remote Support -
Gradle Build Cache - Modularize โข Reduce the number of
inputs per task and make them more stable โข Watch Siggiโs talk about graph theory โข Gradle build scans to observe performance -
Gradle Remote Cache โข Do it: https://docs.gradle.com/build-cache-node/ โข 90 Days,
300GB, use validation scripts โข Most local and CI runs will benefit from build cache hits โข Free -
โข Provides support for features beyond remote cache โข Really
helps figure out failures, cache misses, and performance issues across a team โข Looking forward to using test prediction -
Gradle Caches Build Cache ๐ป Configuration Cache Dependency Cache Script
Cache Local Support ๐ป Local Support Remote Support Remote Support -
Gradle Caches Build Cache ๐ป Configuration Cache Dependency Cache Script
Cache Remote Support Local Support Remote Support Remote Support -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker Gradle Build Cache Optimization -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker Gradle Build Cache Optimization -
Control JDK 11 -> JDK 19 40 30 20 10
0 Partial Cache Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker JDK 11 -> JDK 19 -
Upgrade Tooling โWill version X of dependency Y work on
our project?โ -
๐ฅท Shadow Jobs โWill version X of dependency Y work
on our project?โ -
๐ฅท Shadow Jobs Run nightly checks against your project with
latest snapshots of new versions. โWill version X of dependency Y work on our project?โ Zac Sweers -
๐ฅท Shadow Jobs Run nightly checks against your project with
latest snapshots of new versions. โWill version X of dependency Y work on our project?โ Zac Sweers -
JVM Argument Tuning DISCLAIMER: I am not accountable for any
of these settings. If they donโt work for you there are so many reasons why your setup would handle them differently. -
Garbage Collection Algo Tradeoff Each JVM GC algorithm makes a
choice about what they optimize for and how much. -
Garbage Collection Algo Tradeoff Throughput Footprint Latency Transactions per second
Time spent in GC pauses Rough memory footprint size -
ParallelGC Garbage Collection Algo Tradeoff G1GC โข Optimize for speed
โข Maximum footprint โข Might have longer GC pauses โข Balance throughput โข Lower footprint โข Shorter GC pauses -
ParallelGC Garbage Collection Algo Tradeoff G1GC โข Optimize for speed
โข Maximum footprint โข Might have longer GC pauses โข Balance throughput โข Lower footprint โข Shorter GC pauses Use when resource constrained Use when resources allow -
kotlin.daemon.jvm.options When passing arguments, follow these rules: Use the minus
sign - only before the arguments Xmx, XX:MaxMetaspaceSize, and XX:ReservedCodeCacheSize. Separate arguments with commas (,) without spaces. Arguments that come after a space will be used for the Gradle daemon, not for the Kotlin daemon. Kotlin JVM Arguments -
kotlin.daemon.jvm.options When passing arguments, follow these rules: Use the minus
sign - only before the arguments Xmx, XX:MaxMetaspaceSize, and XX:ReservedCodeCacheSize. Separate arguments with commas (,) without spaces. Arguments that come after a space will be used for the Gradle daemon, not for the Kotlin daemon. Kotlin JVM Arguments -
kotlin.daemon.jvm.options When passing arguments, follow these rules: Use the minus
sign - only before the arguments Xmx, XX:MaxMetaspaceSize, and XX:ReservedCodeCacheSize. Separate arguments with commas (,) without spaces. Arguments that come after a space will be used for the Gradle daemon, not for the Kotlin daemon. Kotlin JVM Arguments -
kotlin.daemon.jvmargs You can add the kotlin.daemon.jvmargs property in the gradle.properties
fi le: kotlin.daemon.jvmargs=-Xmx1500m -Xms=500m Kotlin JVM Arguments -
kotlin.daemon.jvmargs You can add the kotlin.daemon.jvmargs property in the gradle.properties
fi le: kotlin.daemon.jvmargs=-Xmx1500m -Xms=500m Using spaces at the beginning will cause all arguments to be ignored Kotlin JVM Arguments -
Xmx (max) JVM Heap Size Xms (min) โข Amount of
memory it takes to compile your biggest task / module. โข For most projects this is going to be your main app moduleโs minification step. โข Somewhere between 80 and 100% of Xmx. โข Heap only grows when GC happens, so increasing it avoids this penalty. -
MaxMetaspaceSize Metaspace CompressedClassSpaceSize โข class & non-class space โข unlimited
by default โข virtual size of compressed classes โข defaults to 1GB -
CompressedOops Metaspace CompressedClassPointers โข Defaults on < 30GB heap โข
Uses 4 fewer bytes โข Restricts memory heap to 32GB โข Available if CompressedOops is on -
What if we turn off CompressedClassSpace + CompressedOops? 20 15
10 5 0 On Off On Off minutes -
Metaspace CompressedOops & unlimited MaxMetaspace is going to be better
for majority of Android projects. -
Metaspace CompressedOops & unlimited MaxMetaspace is going to be better
for majority of Android projects. (so stick with the defaults) -
CodeCache To determine what number you should use, measure via
โXX:+PrintCodeCache -
SoftRefLRUPolicyMSPerMB The number of milliseconds to hold onto soft references
per MB of heap size, default 1000 -
SoftRefLRUPolicyMSPerMB The number of milliseconds to hold onto soft references
per MB of heap size, default 1000 = 2h 16m 32s 8GB Heap @ 1000 MS Policy -
SoftRefLRUPolicyMSPerMB The number of milliseconds to hold onto soft references
per MB of heap size, default 1000 = 2h 16m 32s 8GB Heap @ 1000 MS Policy 8GB Heap @ 10 MS Policy = 0h 1m 22s -
SoftRefLRUPolicyMSPerMB The number of milliseconds to hold onto soft references
per MB of heap size, default 1000 = 2h 16m 32s 8GB Heap @ 1 MS Policy 8GB Heap @ 1000 MS Policy = 0h 0m 8s 8GB Heap @ 10 MS Policy = 0h 1m 22s -
Gradle Max Workers --max-workers The maximum number of active workers
to allow Should probably be number of performance cores, possibly 1-2 less Will not spawn more workers is memory heap requirements cannot be met -
jemalloc / tcmalloc Memory fragmentation slows down builds, use a
better malloc algorithm -
malloc alternatives We saw no speed difference with jemalloc, but
it did notice 10% less memory usage -
malloc alternatives Therefore use jemalloc (or tcmalloc) to be able
to run more daemons in parallel with less memory pressure. -
๐ฅท Shadow Jobs 1. Instrument your build with JVM args
as parameters 2. Run parameterized tests 3. Profit What do we actually pick for JVM args? -
โข GC Algo = It Depends (try for Parallel) โข
SoftRefLRUPolicyMSPerMB = 1 โข CodeCache = 256MB - 512MB โข MaxMetaspace = Some GB or unlimited โข Metaspace = 64MB - 1GB โข Xmx = 4GB - 8GB โข Xms = 3GB - 7GB โข Max Workers=Performance Cores - 2 What do we actually pick? -
โข jcmp for Metaspace โข โXX:+PrintCodeCache for CodeCache โข Measure
CPU & Memory resource usage, lots of tools available JVM Measurement Tools -
Control JVM Optimizations 40 30 20 10 0 Partial Cache
Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker JVM Optimizations -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker JVM Optimizations -
Gradle Caches Build Cache Configuration Cache Dependency Cache Script Cache
Remote Support Remote Support Remote Support ๐ป Local Support -
Gradle Caches Build Cache Configuration Cache Dependency Cache Script Cache
Remote Support Remote Support Remote Support ๐ป Local Support -
Gradle Cache directories ~/.gradle โโโ caches โ โโโ โฎ ~/project
โโโ .gradle โโโ app โโโ build โโโ gradle โโโ โฎ Dependency Cache Script Cache -
Gradle Cache directories ~/project โโโ .gradle โโโ app โโโ build
โโโ gradle โโโ โฎ -
Gradle Cache directories ~/project โโโ .gradle โ โ โ โ
โโโ app โโโ build โโโ gradle โโโ โฎ -
Gradle Cache directories ~/project โโโ .gradle โ โโโ 8.1 โ
โโโ 8.2 โ โโโ โฎ โ โโโ configuration-cache โโโ app โโโ build โโโ gradle โโโ โฎ -
~/project โโโ .gradle โ โโโ 8.1 โ โโโ 8.2 โ
โโโ โฎ โ โโโ configuration-cache โโโ app โโโ build โโโ gradle โโโ โฎ Configuration Cache Gradle Cache directories -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/modules-2 .gradle/<< gradle_version >>
.gradle/configuration-cache ci-cache.yml -
As of Gradle 8.1 encryption was added. Asking Gradle support
- configuration cache on CI is unsupported Gradle Configuration Cache on CI -
As of Gradle 8.1 encryption was added. Gradle's response has
been that configuration cache on CI is not supported Gradle Configuration Cache on CI -
As of Gradle 8.1 encryption was added. Gradle's response has
been that configuration cache on CI is not supported. But we persisted anyway... Gradle Configuration Cache on CI -
Gradle Configuration Cache on CI Environment Variable Environment Variables Prefixed
File system Entry File System property Value from custom source 35 1 2007 4 52 5 build/reports/configuration-cache/4tnz..i67j/27o6..b0jl/configuration-cache-report.html We looked at the reports for all inputs -
But despite everything 100% of inputs being consistent we continued
to get an unhelpful error message: Gradle Configuration Cache on CI -
Gradle Configuration Cache on CI Calculating task graph as no
configuration cache is available for tasks -
Gradle Configuration Cache on CI โYou need to cache the
encryption key.โ โ Inaki Villar -
Gradle Configuration Cache on CI Caveat to this method -
you will be caching any secrets used by this build, so either: โข Only use this for builds that do not rely on secrets โข Knowingly store this with the security risk -
Gradle User Home directory ~/.gradle โโโ caches โ โโโ 8.1
โ โ โฆ โ โโโ 8.4 โ โ โโโ cc-keystore โ โ โโโ cache.properties โ โ โโโ cc-keystore.lock โ โ โโโ gradle.keystore โ โโโ โ โโโ buildcacheโ1 โ โโโ jars-9 โ โโโ journal-1 Configuration Cache Encryption -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/modules-2 .gradle/<< gradle_version >>
.gradle/configuration-cache ci-cache.yml -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/<< gradle_version >>/cc-keystore ~/.gradle/caches/modules-2
.gradle/<< gradle_version >> .gradle/configuration-cache ci-cache.yml -
Gradle Configuration Cache on CI Calculating task graph as no
configuration cache is available for tasks -
unit_tests: docker: - image: circleci/android:api-34-node steps: - run: name: Clean
Gradle Cache command: | find . -type f -name '*.lock' -delete find . -type f -name 'gc.properties' -delete find ~/.gradle -type f -name '*.lock' -delete find ~/.gradle -type f -name 'gc.properties' -delete when: always - save_cache: paths: - ~/.gradle/caches/<< parameters.gradle_version >>/ generated-gradle-jars - ~/.gradle/caches/<< parameters.gradle_version >>/ kotlin-dsl - .gradle/configuration-cache - ~/.gradle/caches/<< parameters.gradle_version >>/ cc-keystore - .gradle/<< parameters.gradle_version >> config.yml -
unit_tests: docker: - image: circleci/android:api-34-node steps: - run: name: Clean
Gradle Cache command: | find . -type f -name '*.lock' -delete find . -type f -name 'gc.properties' -delete find ~/.gradle -type f -name '*.lock' -delete find ~/.gradle -type f -name 'gc.properties' -delete when: always - save_cache: paths: - ~/.gradle/caches/<< parameters.gradle_version >>/ generated-gradle-jars - ~/.gradle/caches/<< parameters.gradle_version >>/ kotlin-dsl - .gradle/configuration-cache - ~/.gradle/caches/<< parameters.gradle_version >>/ cc-keystore - .gradle/<< parameters.gradle_version >> config.yml ๐คฆ -
Gradle Configuration Cache on CI Calculating task graph as configuration
cache cannot be reused because an input to task โ:gradle-plugin:generateExternalPluginSpecBuilders' has changed. -
Gradle Configuration Cache on CI Calculating task graph as configuration
cache cannot be reused because an input to task โ:gradle-plugin:generateExternalPluginSpecBuilders' has changed. -
โGradle has compilation avoidance for non- ABI changes in included
builds, but due to a bug any inline function would cause all build scripts to be recompiled even when there is a non-ABI change.โ - Nicklas Ansman Gradle Configuration Cache on CI -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/<< gradle_version >>/cc-keystore ~/.gradle/caches/modules-2
.gradle/<< gradle_version >> .gradle/configuration-cache gradle-plugin/build/pluginDescriptors ci-cache.yml -
Gradle Configuration Cache on CI Could not load the value
of field `patterns` of `org.gradle.configurationcache.serialization.codecs.DirectoryTree Spec` bean found in field `fileSystemInputs` of `org.gradle.configurationcache.fingerprint.ConfigurationCacheFing erprint$WorkInputs` bean found in Gradle runtime. > Failed to instrument class org/jetbrains/kotlin/gradle/tasks/ KotlinCompile$ScriptFilterSpec in ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:gradle- plugin]:buildSrc[:gradle-plugin]:root-project[:gradle-plugin] (export)} -
Gradle Configuration Cache on CI Could not load the value
of field `patterns` of `org.gradle.configurationcache.serialization.codecs.DirectoryTree Spec` bean found in field `fileSystemInputs` of `org.gradle.configurationcache.fingerprint.ConfigurationCacheFing erprint$WorkInputs` bean found in Gradle runtime. > Failed to instrument class org/jetbrains/kotlin/gradle/tasks/ KotlinCompile$ScriptFilterSpec in ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:gradle- plugin]:buildSrc[:gradle-plugin]:root-project[:gradle-plugin] (export)} -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/<< gradle_version >>/cc-keystore ~/.gradle/caches/modules-2
.gradle/<< gradle_version >> .gradle/configuration-cache gradle-plugin/build/pluginDescriptors ci-cache.yml -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/<< gradle_version >>/cc-keystore ~/.gradle/caches/modules-2
.gradle/<< gradle_version >> .gradle/configuration-cache gradle-plugin/build ci-cache.yml -
~/.gradle/caches/<< gradle_version >>/generated-gradle-jars ~/.gradle/caches/<< gradle_version >>/kotlin-dsl ~/.gradle/caches/<< gradle_version >>/cc-keystore ~/.gradle/caches/modules-2
~/.gradle/caches/jars-9 ~/.gradle/caches/transforms-3 .gradle/<< gradle_version >> .gradle/configuration-cache gradle-plugin/build ci-cache.yml -
โWow, I was prepared for a faster PR time but
that was blazingโ - Jacob Duron Gradle Configuration Cache on CI -
Gradle Caches Build Cache Configuration Cache Dependency Cache Script Cache
Remote Support Remote Support Remote Support ๐ป Local Support -
Gradle Caches Build Cache Configuration Cache Dependency Cache Script Cache
Remote Support Remote Support Remote Support Remote Support -
Control Gradle Configuration Cache Reuse 40 30 20 10 0
Partial Cache Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Control Gradle Configuration Cache Reuse 40 30 20 10 0
Partial Cache Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
40 30 20 10 0 Gradle Configuration Cache Reuse Control
Partial Cache Hit Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Overhead Cost Optimizations ๐ฆ git clone pulls 400 MB big
images (2.5 GB) Minutes to save cache ~60 seconds to restore cache -
image size 2560 2048 1536 1024 512 Circle/ Android 0
JRE Bare megabytes Android -
download & extract time 75 60 45 30 15 0
seconds Circle/ Android JRE Bare Android -
download & extract time 75 60 45 30 15 0
seconds Circle/ Android JRE Bare Android -
500 400 300 200 100 0 default no blobs no
trees shallow megabytes clone & checkout size -
75 60 45 30 15 0 seconds default no blobs
no trees shallow clone & checkout time -
75 60 45 30 15 0 seconds default no blobs
no trees shallow clone & checkout time -
Why did we go with treeless if its not the
fastest? Shallow is faster, but it comes with a heavy penalty for any additional git operations clone & checkout time -
prune 40 30 20 10 0 Control Partial Cache Hit
Cache Hit Core Change Cache Hit Leaf Change minutes cache save gradle execution gradle configuration cache restore git Docker -
Control 40 30 20 10 0 Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes prune cache save gradle execution gradle configuration cache restore git Docker -
40 30 20 10 0 Control Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes clone optimization cache save gradle execution gradle configuration cache restore git Docker -
40 30 20 10 0 Control Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes clone optimization cache save gradle execution gradle configuration cache restore git Docker -
40 30 20 10 0 Control Partial Cache Hit Cache
Hit Core Change Cache Hit Leaf Change minutes Present Day Unit Test Runs cache save gradle execution gradle configuration cache restore git Docker -
Present Day CI Runs 12 9 6 3 0 Unit
Tests Release R8 UI Tests Unit Tests Release R8 UI tests minutes -
CI Speed Optimizations Cache Dependencies Cache Build Tasks Cache Configuration
JVM Tuning Compiler Flags ๐ฆ treeless or shallow clone prune images ๐ ๐ฆ Cache Optimizations ๐ฉ -
CI Speed Optimizations Cache Dependencies Cache Build Tasks Cache Configuration
JVM Tuning Compiler Flags ๐ฆ treeless or shallow clone prune images ๐ ๐ฆ Cache Optimizations ๐ฉ ๐ง โ โ โ โ Future Talk -
Topics not covered ๐ฉ๐ป Local Dev Environment ๐ญ Parallelization ๐ธ
Automatic Screenshot Testing -
Metaspace Citations Thomas Stรผfe Blog https://stuefe.de/posts/metaspace/what-is-metaspace/ https://stuefe.de/posts/metaspace/metaspace-architecture/ https://stuefe.de/posts/metaspace/what-is-compressed-class-space/ https://stuefe.de/posts/metaspace/sizing-metaspace/ https://stuefe.de/posts/metaspace/analyze-metaspace-with-jcmd/
Oracle Class Metadata, PermGen and changes to native memory allocation -
Gradle Documentation Gradle Files & Directories https://docs.gradle.org/current/userguide/directory_layout.html Gradle CI Ephemeral
Best Practices https://docs.gradle.org/current/userguide/ dependency_resolution.html#sub:ephemeral-ci-cache Gradle Recommends using Daemons for CI https://docs.gradle.org/current/userguide/ gradle_daemon.html#continuous_integration -
Kotlin JVM Args Documentation New Method https://kotlinlang.org/docs/gradle-compilation-and-caches.html#kotlin- daemon-jvmargs-property Deprecated Method
https://kotlinlang.org/docs/gradle-compilation-and-caches.html#kotlin- daemon-jvm-options-system-property -
JDK Version Documentation JDK Release Notes Summaries for GC Algo
Changes 19 | 20 | 21 JVM SoftReferences Tuning CodeCache