Transcript
Page 1: OnAndroidConf 2013: Accelerating the Android Platform Build

Accelerating the Android Platform Build

David Rosen, Product [email protected]@adr0sen

OnAndroidConf 2013

Page 2: OnAndroidConf 2013: Accelerating the Android Platform Build

What’s this Android buzz all about?

2

Page 3: OnAndroidConf 2013: Accelerating the Android Platform Build

Qualcomm Reference Design Program<60 days TTM, and pushing for faster

Source: http://www.qualcomm.com/connect/analyst-relations/events/americas-analyst-summit-2012

Page 4: OnAndroidConf 2013: Accelerating the Android Platform Build

Android Development LandscapeReal-world challenges at large APAC mobile device maker

Page 5: OnAndroidConf 2013: Accelerating the Android Platform Build

Automotive6%

Mobile38%

Consumer electron-ics

18%

In-dus-trial con-trol and au-

toma-tion6%

Med-ical4%

Mili-tary/aerospac

e3%

Other25%

Users of Android by Vertical

Electric Cloud Android/Embedded Survey(Q1 2013)

• Survey• Focused on Android

development & delivery

• Global embedded contacts in Electric Cloud marketing lists

• 350+ respondents• 175+ Android

Page 6: OnAndroidConf 2013: Accelerating the Android Platform Build

Android Delivery Process Today

Technical Challenges

• Slow Android Builds• Slow, Complex CTS

Testing• Complex B-T-R Matrix• Custom Testing –

Volume, Complexity

Negative Business Impacts

• Slow Time to Market• Poor Quality of products• Poor productivity of

teams

Less than 1 hour; 22.5%

1-4 hours; 57.5%

4-8 hours; 15.0%

More than 8 hours; 5.0%

Avg. time to execute CTS

Less than 5 minutes; 7.8%

5-20 min-utes; 21.0%

20 minutes - 1 hour; 28.8%

1-4 hours; 27.0%

More than 4 hours; 15.3%

Avg. release build time

Page 7: OnAndroidConf 2013: Accelerating the Android Platform Build

Accelerating the Android build

Page 8: OnAndroidConf 2013: Accelerating the Android Platform Build

Why look at Android builds?

• Android is everywhere• 68% of global mobile phone market share1

• Explosion of non-phone applications• Automotive (Saab, Renault)• Entertainment (Ouya, Nvidia)• Exercise equipment (NordicTrack)• Rice cookers! (Panasonic)

• Android is everywhere• … and that means thousands of developers building Android

• What if we can make those builds faster?• How would your development process change?• How much more could you achieve?

1 Source: Gartner, February 2013

Page 9: OnAndroidConf 2013: Accelerating the Android Platform Build

What is (and is not) covered in this part of the talk?

• Build acceleration techniques fall into two broad categories:• Hardware improvements like faster CPU’s and better disks• Software improvements like smarter build tools and faster compilers

• In general, hardware and software improvements are complimentary• If you want the fastest possible builds, leverage both!

• This talk is about software techniques for build acceleration• Given a fixed hardware platform, how fast can we build Android?• Or, what do you do when you reach the limits of your hardware?

Page 10: OnAndroidConf 2013: Accelerating the Android Platform Build

January 2009

July 2009

January 2010

July 2010

January 2011

July 2011

January 2012

July 2012

January 2013

0

2,000,000

4,000,000

6,000,000

8,000,000

10,000,000

12,000,000

14,000,000

16,000,000

18,000,000

Linux Kernel

Android

Mozilla Firefox

Chromium

Webkit

AOSP LOC Evolution

Jan 2009 – Jan 20131

4.0.1 ICS

4.1.1 JB

2.3.4 GB

4.2.2 JB

2.2 Froyo

1 Source: http://www.ohloh.net, http://en.wikipedia.org/wiki/Android_version_history (February 2013)

Page 11: OnAndroidConf 2013: Accelerating the Android Platform Build

2.2 2.3.4 4.0.1 4.1.1 4.2.2 00:00

00:14

00:28

00:43

00:57

01:12

01:26

01:40

0

2,000,000

4,000,000

6,000,000

8,000,000

10,000,000

12,000,000

14,000,000

16,000,000

18,000,000

+15%

+123%

+19%+2%

+30%+12%

+17% +2%

Build Time

LOC

AOSP Build Evolution

Android Version Release Date LOC1 LOC Growth %

GNU Make Build Time2

Build TimeGrowth %

2.2 May 2010 8,837,858 - 28m55s -

2.3.4 April 2011 11,492,324 30% 33m10s 15%

4.0.1 October 2011 12,827,330 12% 1h13m54s 123%

4.1.1 July 2012 15,028,331 17% 1h28m11s 19%

4.2.2 February 2013 15,266,8033 2% 1h32m56s 2%

1 http://www.ohloh.net, 2 Builds performed on 8-core 16GB RAM server, 3 LOC data as of December 2012

Page 12: OnAndroidConf 2013: Accelerating the Android Platform Build

Common wisdom about Android builds

• I can just…• … add more cores• … use distcc• … use ccache

• “The Android build is as optimized as it can be!”

Page 13: OnAndroidConf 2013: Accelerating the Android Platform Build

The common wisdom is wrong.

Page 14: OnAndroidConf 2013: Accelerating the Android Platform Build

Sidebar: how much faster is “interesting”?

• Some large mobile device makers run > 50K builds/week• At 15 minutes per build that’s 12,500 hours of build time• A reduction of just one minute would save 800 hours every week

• What about wait time?

• Faster builds = more iterations• Faster builds = higher quality• Faster builds = lower time to market

Page 15: OnAndroidConf 2013: Accelerating the Android Platform Build

How fast is GNU make?

• Best time: ~15m• 48-cores• 128GB RAM

Page 16: OnAndroidConf 2013: Accelerating the Android Platform Build

Problem: Visibility

• Knowing the end-to-end time is great but not actionable• We need visibility

• Where is the time going?• What are the bottlenecks?• Are there opportunities for improvement?

• How do we get that visibility?• Instrument the build… somehow! strace, echo, hack gmake, or…

• ElectricInsight• Visualization and analysis of builds run with ElectricMake• Let’s pump this build through emake and see how it looks!

Page 17: OnAndroidConf 2013: Accelerating the Android Platform Build

Solution: ElectricInsight

Page 18: OnAndroidConf 2013: Accelerating the Android Platform Build

What can we see from here?

• An ideal build would look like a tightly packed box• Overall looks almost perfect – well done, Android team!

• But! a couple of things stand out:• Crazy long parse time1

• Gaps at the end of the build, indicative of serializations• Some very long serial chunks at the bottom of graph

• We’ll investigate these issues, but first: what if we just use more cores?

1 emake parsing may be slower than gmake parsing

Page 19: OnAndroidConf 2013: Accelerating the Android Platform Build

Longest serial chain

• Best possible runtime is about 15m

Best possible is about 15m

Page 20: OnAndroidConf 2013: Accelerating the Android Platform Build

Projected runtime with more cores

Page 21: OnAndroidConf 2013: Accelerating the Android Platform Build

What else can we learn?

• Lots of non-compile work in the build - ~25% of total time

Page 22: OnAndroidConf 2013: Accelerating the Android Platform Build

Problem: long parse time

• Why do we build?• To transform sources into deliverables (programs, docs, etc).

• Does parsing makefiles transform sources into deliverables?• Nope.

• Parsing makefiles is pure overhead• But you have to tell make what to do somehow• Unless you want to manually invoke the compiler, linker, etc.

Page 23: OnAndroidConf 2013: Accelerating the Android Platform Build

Solution: parse avoidance

• What if we don’t parse (every time)?• Makefiles don’t change very often, so why reparse every time?

• Reuse parse results from a previous build, as long as…• Makefiles are unchanged (MD5)• Command-line is unchanged• Environment is unchanged

• How do we do it?• Electric Make already has parse results in a reloadable form, just

need to add cache management• GNU make doesn’t, but could be modified

Page 24: OnAndroidConf 2013: Accelerating the Android Platform Build

Parse avoidance impactBuild time reduced to about 13m30s

Page 25: OnAndroidConf 2013: Accelerating the Android Platform Build

Problem: serializations

• Gaps in visualization suggest serializations

• Q: How many dependencies are there in the Android build?

• A: More than you think!

Page 26: OnAndroidConf 2013: Accelerating the Android Platform Build

Android Dependency Graph

• Dump all makefile rules• 100,000 files/targets• 1,990,628 dependencies

Page 27: OnAndroidConf 2013: Accelerating the Android Platform Build

Dependencies in Android

• ~19 dependencies per file: why so many?• Consider a typical build structure:

• Some files will have many dependencies• Most have only a few• What is going on in Android?

lib.a: foo.o bar.ofoo.o: foo.c foo.h util.hbar.o: bar.c bar.h util.h

Page 28: OnAndroidConf 2013: Accelerating the Android Platform Build

Superfluous dependencies in Android

• Do we really need all 1.9M dependencies?• The filesystem can tell us!

• Collect a list of files actually used to generate a target• Compare to the list of prerequisites specified in the makefile

• Example:

• Why not run foo.txt and bar.txt in parallel?

foo.txt: echo “Hello” > foo.txt

bar.txt: foo.txtecho “World” > bar.txt

Page 29: OnAndroidConf 2013: Accelerating the Android Platform Build

Actual dependencies in Android

• 100,000 files/targets• 288,804 dependencies

Page 30: OnAndroidConf 2013: Accelerating the Android Platform Build

Specified vs. Actual dependencies in Android

Specified Actual

Page 31: OnAndroidConf 2013: Accelerating the Android Platform Build

Solution: dependency optimization

• Impossible to manually eliminate superfluous dependencies

• Electric Make can prune them automatically• If you use gmake, you can achieve the same effect:

• Remove existing dependency specifications• Generate minimal dependency specifications from emake data• Before:

• After:

$(OBJECTS): %.o: %.cpp $(ALL_HEADERS) $(OTHER_DEPS)$(COMPILE.CC)

$(OBJECTS): %.o: %.cpp$(COMPILE.CC)

foo.o: foo.h util.hbar.o: bar.h util.h generated.h

Page 32: OnAndroidConf 2013: Accelerating the Android Platform Build

Dependency optimization impactBuild time reduced to about 12m30s

Page 33: OnAndroidConf 2013: Accelerating the Android Platform Build

Problem: long serial jobs

• Long serial jobs prohibits further parallelization• Dominates longest serial chain:

• In Android, Javadoc generation is a performance albatross• Typically a long, monolithic job• Not decomposable/parallelizable, not incremental

Page 34: OnAndroidConf 2013: Accelerating the Android Platform Build

• Javadoc generation can be cached• Stash output after running javadoc• Reuse output in future builds if inputs match• Like ccache, but for javadoc

Solution: Javadoc Caching

Carving 4 minutes away from job!

Page 35: OnAndroidConf 2013: Accelerating the Android Platform Build

Javadoc Caching impactBuild time reduced to about 9m30s

Page 36: OnAndroidConf 2013: Accelerating the Android Platform Build

Summary

• Google has done a great job of optimizing Android builds• But there’s still room for improvement!

• By caching parse results and javadoc output while pruning dependencies, we have shown to carve off 5m+ or ~37% from build

24 26 30 32 34 38 42 46 4800:00

02:24

04:48

07:12

09:36

12:00

14:24

16:48

19:12

21:36

19:3017:45

15:00

15:00

11:55

09:30

Gmake

Emake

Page 37: OnAndroidConf 2013: Accelerating the Android Platform Build

Questions?David Rosen, Product [email protected]@adr0senhttp://www.electric-cloud.com/eade


Top Related