Slide 1

Slide 1 text

Faster Builds on Android From 2 Minutes to 2 Seconds @muffls Philipp Hofmann

Slide 2

Slide 2 text

Why is build speed important? Photo by Chris Liverani on Unsplash

Slide 3

Slide 3 text

How often do you hit compile?

Slide 4

Slide 4 text

10 - 100 times per day?

Slide 5

Slide 5 text

From 2 minutes to 2 seconds.

Slide 6

Slide 6 text

We save 118 seconds.

Slide 7

Slide 7 text

Around 20 minutes to 2 hours per day.

Slide 8

Slide 8 text

Around 1,6 to 10 hours per week.

Slide 9

Slide 9 text

Reduce by 5 seconds.

Slide 10

Slide 10 text

20 builds * 5s * 10 devs * 5 days = 1,4 hours / week

Slide 11

Slide 11 text

100 builds * 5s * 10 devs * 5 days = 9,6 hours / week

Slide 12

Slide 12 text

What do you do when you have to wait 2 minutes? Photo by NordWood Themes on Unsplash

Slide 13

Slide 13 text

Or just 20 seconds? Photo by NordWood Themes on Unsplash

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Photo by Stefan Cosma on Unsplash

Slide 16

Slide 16 text

Multitasking is killing your brain.

Slide 17

Slide 17 text

Multitasking lets your IQ drop significantly.

Slide 18

Slide 18 text

Like skipping whole night sleep.

Slide 19

Slide 19 text

Or smoking weed. Image Source

Slide 20

Slide 20 text

Knowing there is an unread email can reduce your IQ by 10 points!

Slide 21

Slide 21 text

Multitasking is especially bad for men.

Slide 22

Slide 22 text

It can reduce the IQ up to 15 points.

Slide 23

Slide 23 text

Turning you into a cognitive equivalent of an 8-year-old.

Slide 24

Slide 24 text

Multitasking Is Killing Your Brain CREDIT: Getty Images

Slide 25

Slide 25 text

Slow Builds Test automation is a pain. Slow Tests

Slide 26

Slide 26 text

Faster Builds

Slide 27

Slide 27 text

More Frequent Feedback Faster Builds

Slide 28

Slide 28 text

Faster Development More Frequent Feedback Faster Builds

Slide 29

Slide 29 text

Faster Development More Frequent Feedback Faster Builds

Slide 30

Slide 30 text

Faster Development More Frequent Feedback Faster Builds

Slide 31

Slide 31 text

Faster Development More Frequent Feedback Faster Builds

Slide 32

Slide 32 text

Faster Development More Frequent Feedback Faster Builds

Slide 33

Slide 33 text

Faster Development More Frequent Feedback Faster Builds Faster Builds Pyramid

Slide 34

Slide 34 text

• Measure Your Builds • Quick Wins to Fasten Your Builds • Modularisation and Build Speed • Some additional information about the topic on the chart • Maybe some numbers or a background information about some insights • Here is just another placeholder text to visualise the look of a filled info box INFO BOX Topics

Slide 35

Slide 35 text

Measure Your Builds Photo by Annie Spratt on Unsplash

Slide 36

Slide 36 text

$ ./gradlew assembleDebug --scan

Slide 37

Slide 37 text

$ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no]

Slide 38

Slide 38 text

$ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes

Slide 39

Slide 39 text

$ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted.

Slide 40

Slide 40 text

$ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted. Publishing build scan...

Slide 41

Slide 41 text

$ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted. Publishing build scan... https://gradle.com/s/glklref6wdxr6

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Create Build Scans https://guides.gradle.org/creating-build-scans/

Slide 47

Slide 47 text

$ ./gradlew assembleDebug --profile

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Profile Your Build https://developer.android.com/studio/build/optimize-your-build#profile

Slide 51

Slide 51 text

Gradle Profiler https://github.com/gradle/gradle-profiler

Slide 52

Slide 52 text

Talaiot https://github.com/cdsap/Talaiot

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

$ ./gradlew clean cleanBuildCache

Slide 55

Slide 55 text

Measure Optimise

Slide 56

Slide 56 text

Quick Wins to Fasten Your Builds Photo by Richard R Schünemann on Unsplash

Slide 57

Slide 57 text

Update your Tools Photo by Todd Quackenbush on Unsplash

Slide 58

Slide 58 text

Update Gradle

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Improving build speed in Android Studio https://medium.com/androiddevelopers/improving-build-speed-in-android- studio-3e1425274837

Slide 62

Slide 62 text

Update JVM

Slide 63

Slide 63 text

Update Android Studio and SDK Tools

Slide 64

Slide 64 text

Update Android Plugin for Gradle

Slide 65

Slide 65 text

• Gradle • JVM • Android Studio and SDK Tools • Android Plugin for Gradle Update

Slide 66

Slide 66 text

Use Apply Changes

Slide 67

Slide 67 text

gradle.properties

Slide 68

Slide 68 text

Caching org.gradle.caching=true

Slide 69

Slide 69 text

If neither a task’s inputs nor its output have changed since the last time it was run, Gradle will not run it again.

Slide 70

Slide 70 text

Enabled by default. Since Android Plugin 2.3.0 https://developer.android.com/studio/build/build-cache

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Gradle Build Cache https://docs.gradle.org/current/userguide/build_cache.html

Slide 73

Slide 73 text

Incremental Compilation kotlin.incremental=true

Slide 74

Slide 74 text

Incremental annotation processor kapt.incremental.apt=true

Slide 75

Slide 75 text

Parallel Builds org.gradle.parallel=true

Slide 76

Slide 76 text

Create a build variant for development

Slide 77

Slide 77 text

flavorDimensions "mode" productFlavors { dev { dimension "mode" resConfigs "en", "xxhdpi" buildConfigField "long", "TIMESTAMP", "0L" } full { dimension "mode" } }

Slide 78

Slide 78 text

Quick wins 1. Update your Tools 2. Use Apply Changes 3. Caching 4. Incremental Compilation 5. Parallel Builds 6. Build Variant for Develop Photo by Richard R Schünemann on Unsplash

Slide 79

Slide 79 text

More Stuff

Slide 80

Slide 80 text

Scope annotation processing

Slide 81

Slide 81 text

Apply only needed plugins

Slide 82

Slide 82 text

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'maven-publish' apply plugin: 'kotlin-kapt' apply plugin: 'talaiot' apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'org.jlleitschuh.gradle.ktlint'

Slide 83

Slide 83 text

Improving the Performance of Gradle Builds https://guides.gradle.org/performance/

Slide 84

Slide 84 text

Check your memory settings org.gradle.jvmargs= -Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Slide 85

Slide 85 text

Java Performance Tuning https://dzone.com/articles/java-performance-tuning

Slide 86

Slide 86 text

Optimize your build speed https://developer.android.com/studio/build/optimize-your-build

Slide 87

Slide 87 text

19 tips for Gradle in Android projects — 2019 Edition https://medium.com/google-developer-experts/19-tips-for-gradle-in-android- projects-2019-edition-11af704eb06e

Slide 88

Slide 88 text

Modularisation

Slide 89

Slide 89 text

Modules can speed up your build, but can also slow down your build.

Slide 90

Slide 90 text

1. Build modules in parallel

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

No content

Slide 95

Slide 95 text

Example

Slide 96

Slide 96 text

Small app with one module.

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

Optimise • Update gradle and gradle plugin • Update Kotlin • Enable parallel builds and incremental compilation • Split up code into multiple modules

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Reduced build time for around 25%.

Slide 103

Slide 103 text

2. Compilation avoidance

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

api implementation vs

Slide 107

Slide 107 text

api implementation Module A Module B

Slide 108

Slide 108 text

Module A Module B Module C Foo api

Slide 109

Slide 109 text

Module A Module B Module C Foo api

Slide 110

Slide 110 text

Module A Module B Module C Foo api

Slide 111

Slide 111 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api

Slide 112

Slide 112 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api

Slide 113

Slide 113 text

Module A Module B Module C implementation Foo Module A Module B Module C Foo api

Slide 114

Slide 114 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api

Slide 115

Slide 115 text

Module A Module B Module C implementation Foo Module A Module B Module C Foo api

Slide 116

Slide 116 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail

Slide 117

Slide 117 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail

Slide 118

Slide 118 text

Module A Module B Module C Foo implementation Module A Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail

Slide 119

Slide 119 text

@FMuntenescu Florina Muntenescu

Slide 120

Slide 120 text

Change

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

18 seconds when in layout

Slide 124

Slide 124 text

7 seconds when in Fragment

Slide 125

Slide 125 text

Change

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

18 seconds when in layout

Slide 129

Slide 129 text

6 seconds when in layout

Slide 130

Slide 130 text

6 seconds when in layout 3 times faster

Slide 131

Slide 131 text

7 seconds when in Fragment

Slide 132

Slide 132 text

3 seconds when in Fragment

Slide 133

Slide 133 text

3 seconds when in Fragment 2,3 times faster

Slide 134

Slide 134 text

Change Run

Slide 135

Slide 135 text

65 seconds

Slide 136

Slide 136 text

Change Run

Slide 137

Slide 137 text

Change Run

Slide 138

Slide 138 text

65 seconds

Slide 139

Slide 139 text

9 seconds

Slide 140

Slide 140 text

9 seconds 7 times faster

Slide 141

Slide 141 text

Build just what you need • Build only the code you want to check. • Let you iterate faster on your feature modules.

Slide 142

Slide 142 text

3. Faster Tests

Slide 143

Slide 143 text

Run tests 15 seconds

Slide 144

Slide 144 text

Run tests 4 seconds

Slide 145

Slide 145 text

I promised 2 seconds.

Slide 146

Slide 146 text

Plain Kotlin or Java No Android dependencies

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

https://medium.com/google-developer-experts/19-tips-for-gradle-in-android-projects-2019-edition-11af704eb06e :libjava:assemble of the base java plugin

Slide 149

Slide 149 text

https://medium.com/google-developer-experts/19-tips-for-gradle-in-android-projects-2019-edition-11af704eb06e :lib1:assembleDebug of the com.android.library

Slide 150

Slide 150 text

Create pure Java Kotlin / Libraries

Slide 151

Slide 151 text

Advantages of Multiple Modules

Slide 152

Slide 152 text

Advantages of Multiple Modules 1. Build modules in parallel 2. Compilation avoidance 3. Faster tests 4. And all the other advantages … (Reusability, Maintainability, SOLID, …)

Slide 153

Slide 153 text

Sum it up

Slide 154

Slide 154 text

Photo by Richard R Schünemann on Unsplash Quick wins 1. Update your tools 2. Use Apply Changes 3. Use Gradle caching 4. Incremental compilation 5. Parallel builds 6. Build variant for develop

Slide 155

Slide 155 text

Create pure Java Kotlin / Libraries

Slide 156

Slide 156 text

Advantages of multiple modules 1. Build modules in parallel 2. Compilation avoidance 3. Faster tests

Slide 157

Slide 157 text

I optimise the build speed!

Slide 158

Slide 158 text

Measure Optimise

Slide 159

Slide 159 text

Faster Builds

Slide 160

Slide 160 text

More Frequent Feedback Faster Builds

Slide 161

Slide 161 text

Faster Development More Frequent Feedback Faster Builds

Slide 162

Slide 162 text

@muffls Philipp Hofmann Faster Development More Frequent Feedback Faster Builds

Slide 163

Slide 163 text

@muffls Philipp Hofmann Faster Development More Frequent Feedback Faster Builds