Slide 1

Slide 1 text

A Journey in Android Developer Productivity Cash App & Gradle

Slide 2

Slide 2 text

How Cash App Does Builds

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

The Tools We Used

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

./gradlew app:assembleDebug

Slide 10

Slide 10 text

./gradlew app:assembleDebug --scan

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Biggest wins and findings

Slide 18

Slide 18 text

What we discovered - Discovered negative savings from the remote cache 
 
 - After optimizations and applying the cache fix plugin, most instances of negative savings were eliminated, even in East Coast regions. 
 
 - Wire plugin cacheability issues 
 
 - The configuration for enabling the remote cache was not working properly 
 
 - Unnecessary VPN issues causing long build times

Slide 19

Slide 19 text

After identifying and fixing cache misses avoidance savings from the remote cache started to increase

Slide 20

Slide 20 text

AssembleDebug Build Time Down by ~50%

Slide 21

Slide 21 text

Remote Cache Saving CI Builds an average ~8 min per build CI Compute Resource Savings from remote cache: 55 Days & 16 hours per week

Slide 22

Slide 22 text

Optimizing for your expensive build tasks

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

apply plugin: 'com.android.library ' apply plugin: 'org.jetbrains.kotlin.android ' apply plugin: 'org.jetbrains.kotlin.kapt ' apply plugin: 'org.jetbrains.kotlin.plugin.parcelize ' apply plugin: 'app.cash.paparazzi ' apply plugin: 'app.cash.treehouse'

Slide 28

Slide 28 text

Section Title apply plugin: 'java-library'

Slide 29

Slide 29 text

apply plugin: 'com.android.library '

Slide 30

Slide 30 text

JavaCompile task

Slide 31

Slide 31 text

JavaCompile task class files

Slide 32

Slide 32 text

JavaCompile task class files source files

Slide 33

Slide 33 text

JavaCompile task class files source files target sdk

Slide 34

Slide 34 text

JavaCompile task class files source files target sdk max heap size

Slide 35

Slide 35 text

task task outputs task inputs

Slide 36

Slide 36 text

task task outputs task inputs UP-TO-DATE (aka incremental build)

Slide 37

Slide 37 text

JavaCompile task class files source files target sdk max heap size

Slide 38

Slide 38 text

JavaCompile task A.class A.java JDK 11 4 GB

Slide 39

Slide 39 text

JavaCompile task A.class A.java JDK 11 4 GB EXECUTED

Slide 40

Slide 40 text

JavaCompile task A.class, B.class A.java, B.java JDK 11 4 GB

Slide 41

Slide 41 text

JavaCompile task A.class, B.class A.java, B.java JDK 11 4 GB EXECUTED

Slide 42

Slide 42 text

JavaCompile task A.class, B.class A.java, B.java JDK 11 4 GB UP-TO-DATE x 2

Slide 43

Slide 43 text

JavaCompile task A.class A.java JDK 11 4 GB

Slide 44

Slide 44 text

JavaCompile task A.class A.java JDK 11 4 GB CACHED echo “org.gradle.caching=true” >> gradle.properties

Slide 45

Slide 45 text

Speeding Up Local Builds with the Remote Build Cache

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Average AssembleDebug savings from the remote cache were low: 20 sec wall clock time

Slide 51

Slide 51 text

private void addOsXMetadata() { buildScan.background { def json = new JsonSlurper( ) def ip = exec('curl', '-s', 'https://ipinfo.io/ip' ) def ge o if (ip) { geo = json.parseText ( exec('curl', '-s', “https://json.geoiplookup.io/$ip” ) ) } if (ip && geo) { value 'OS: Location', "${geo.city}, ${geo.region}, ${geo.country} " value 'OS: Coordinates', "${geo.latitude}, ${geo.longitude} " } else { value 'OS: Location', 'Unknown ' } } }

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

NYC Developers Saving 1 min 12 sec of build execution time per build from the remote build cache 
 Wall Clock Time: 38 sec of eng time savings

Slide 54

Slide 54 text

SF Developers Saving 3 min 41 sec of build execution time per build from the remote build cache Wall Clock Time: 3 min 10 sec eng time savings

Slide 55

Slide 55 text

SF vs NYC difference in remote cache avoidance savings: 2 min 12 sec East Coast Local AssembleDebug builds: ~709 per week Remote Cache Node in the East Coast would result in... 709 * 2 min 12 sec = 1559.8 min of saved eng time per week * 48 work weeks per year = 1247.84 hours of saved eng time per year

Slide 56

Slide 56 text

$ grep "include '" settings.gradle | wc -l 590

Slide 57

Slide 57 text

$ 590 grep "include '" settings.gradle | wc -l

Slide 58

Slide 58 text

$ grep "include '" settings.gradle | wc -l 590

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Tracking down bottlenecks in 3rd-party plugins

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Time to run task Time loading from cache Avoidance Savings!

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Best practices for build performance

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

@Overrid e T create ( String name, Class type, Action configuratio n ) throws InvalidUserDataException;

Slide 85

Slide 85 text

@Overrid e T create ( String name, Class type, Action configuratio n ) throws InvalidUserDataException;

Slide 86

Slide 86 text

@Overrid e T create ( String name, Class type, Action configuratio n ) throws InvalidUserDataException; @Overrid e TaskProvider register ( String name, Action configurationActio n ) throws InvalidUserDataException ;

Slide 87

Slide 87 text

@Overrid e T create ( String name, Class type, Action configuratio n ) throws InvalidUserDataException; @Overrid e TaskProvider register ( String name, Action configurationActio n ) throws InvalidUserDataException ;

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

Upgrade!

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

$ grep "include '" settings.gradle | wc -l 590

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

buildCache { remote(HttpBuildCache) { if (!isCi) { def pingCache = 'ping -c1 -W1 -q gradle-enterprise.aws.square.com'.execute( ) def isCacheUnreachable = !pingCache.waitFor(2, TimeUnit.SECONDS) | | pingCache.exitValue() == 6 8 if (isCacheUnreachable) { throw new GradleException(... ) } url = 'https://gradle-build-cache.aws.square.com/cache/ ' }

Slide 98

Slide 98 text

boolean isVpnCheckEnabled = hasProperty('com.squareup.cash.vpn.check.enabled') ? getProperty('com.squareup.cash.vpn.check.enabled').toBoolean() : true buildCache { remote(HttpBuildCache) { if (!isCi) { def pingCache = 'ping -c1 -W1 -q gradle-enterprise.aws.square.com'.execute( ) def isCacheUnreachable = !pingCache.waitFor(2, TimeUnit.SECONDS) | | pingCache.exitValue() == 6 8 if (isCacheUnreachable && isVpnCheckEnabled) { throw new GradleException(... ) } url = 'https://gradle-build-cache.aws.square.com/cache/ ' }

Slide 99

Slide 99 text

void addGradleBuildMetadata() { def filteredProperties = project.propertie s .findAll { def key = it.ke y key.startsWith('android.') | | key.startsWith('org.gradle.') | | key.startsWith('com.squareup.') | | key.startsWith('app.cash.') | | key.startsWith('kotlin.') | | key.startsWith('kapt.' ) } filteredProperties.sort()*.ke y .forEach { key - > println("$key = ${filteredProperties[key]}" ) buildScan.value("Property: $key", "${filteredProperties[key]}" ) } }

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

http://bit.ly/34ZN5UQ

Slide 105

Slide 105 text

https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/ jetbrains/kotlin/gradle/tasks/Tasks.kt#L223

Slide 106

Slide 106 text

Recap of Build Performance Essentials Build Scans = your best friend Daemon Parallel Max Workers Configuration On Demand

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

A Journey in Android Developer Productivity Cash App & Gradle @jrodbx @DJRooz