High Performance Android (Big Android BBQ 2015)

E552215dd726801c644470feae8bb41c?s=47 mscheel
October 22, 2015

High Performance Android (Big Android BBQ 2015)

Big Android BBQ in Texas October 22, 2015

E552215dd726801c644470feae8bb41c?s=128

mscheel

October 22, 2015
Tweet

Transcript

  1. October 22, 2015 High Performance Android Mark Scheel (@5280mark) •

    Big Android BBQ • #perfmark #perfmatters
  2. None
  3. THE Big Android BBQ “High Rollers drift slide awesome” @5280mark

    #perfmark @androidbbq #perfmatters
  4. @5280mark #perfmark @androidbbq #perfmatters ✤ yeah, you ✤ are you

    on the twitter? ✤ here is some homework ✤ follow @5280mark ✤ tweet about this talk with #perfmark and #perfmatters ✤ you can look for tweet content hints at the bottom of most every slide ✤ thanks Hey You LOOK HERE ON SCREEN FOR TWEET HINTS
  5. THE Big Android BBQ “High Rollers drift slide awesome” @5280mark

    #perfmark @androidbbq #perfmatters
  6. @5280mark #perfmark @androidbbq #perfmatters Colt-joke ✤ Let’s kick this off

    with a joke “Ugg, @5280mark very low performance on that joke”
  7. @5280mark #perfmark @androidbbq #perfmatters How do we define performance? ✤

    Test everything, every which way ✤ perfect engineer is the engineer that looks both ways when crossing a one way street ✤ Sphero story - performance isn’t always black and white “a great engineer crosses a one way street and looks both ways”
  8. @5280mark #perfmark @androidbbq #perfmatters Sphero Story “@spheroedu #GDGDevFest part of

    #perfmark talk”
  9. @5280mark #perfmark @androidbbq #perfmatters Sphero Story “not sure how this

    story connects to performance … yet”
  10. @5280mark #perfmark @androidbbq #perfmatters Sphero Story “t-shirt story with surprise

    relevance to performance”
  11. @5280mark #perfmark @androidbbq #perfmatters Perforamance at the Org. Level ✤

    Incorporate performance into pair programming ✤ Add performance to code review process ✤ Add performance into continuous integration pipelines ✤ Think about user performance, reach performance, engagement performance and operational efficiency performance “a great engineer crosses a one way street and looks both ways”
  12. @5280mark #perfmark @androidbbq #perfmatters Talk Overview ✤ 1. #consistable ✤

    never hear “but it works on my machine” again ✤ 2. select #perfmatters from 100 dev bytes; ✤ 33 hits from 9 hours of content by 50 speakers “wait, @5280mark about to review 9 hours of video content?!”
  13. @5280mark #perfmark @androidbbq #perfmatters Consistable ✤ Consistent + Reliable =

    Consistable ✤ Imagine a world where project code comes with the machine to build it “#consistable … consistent and reliable build systems”
  14. @5280mark #perfmark @androidbbq #perfmatters Reference Implementation ✤ Mac ✤ Vagrant

    (Ubuntu) ✤ Docker ✤ Jenkins “If the top stops spinning am in the Inception?”
  15. @5280mark #perfmark @androidbbq #perfmatters Vagrant ✤ Vagrant is software that

    creates and configures virtual development environments ✤ Vagrantfile is a recipe for your box, a single file that can be checked in and used to recreate the exact same box over and over ✤ vagrantup.com ✤ commands: $ vagrant up $ vagrant ssh $ vagrant halt $ vagrant destroy “Vagrant - awesome tool, bad name though”
  16. @5280mark #perfmark @androidbbq #perfmatters Docker ✤ Initially written in Go

    ✤ Allows you to “Build, Ship, Run” ✤ Containerization ✤ OSX doesn’t support system-level virtualization even though BSD has Jails (similar) so use Ubuntu via Vagrant (alternative would be boot2docker) “Have you seen the whale logo, its tremendous”
  17. @5280mark #perfmark @androidbbq #perfmatters Jenkins ✤ Java based build tool

    (orgins with Hudson and Oracle dispute) ✤ Continuous Integration software ✤ Monitors execution of builds ✤ Makes it easy for anyone to make a build (source into product) “Have I seen Jenkins on TV before?”
  18. Jenkins

  19. @5280mark #perfmark @androidbbq #perfmatters Jenkins ✤ Consistently and repeatedly build

    your project the same way ✤ Great plugin support, can even publish to Google Play Store ✤ Set up slaves as Docker instances, other Pro Tips … “Jenkins plugins make a great tool even more awesome”
  20. None
  21. @5280mark #perfmark @androidbbq #perfmatters Put them all together ✤ Mac

    is host, has Vagrant inside of it, can see Mac at / vagrant ✤ Docker is inside Vagrant, use host folder to access up: “Super awesome sauce = vagrant + docker + jenkins”
  22. @5280mark #perfmark @androidbbq #perfmatters Consistable ✤ Avoid “Works on my

    machine”, the operational efficiency killer ✤ Vagrant, Docker, Jenkins combine for consistent repeatable build environment, Dev machine same as everywhere else ✤ Incorporate performance measurements? “Works on my machine problems are efficiency killers”
  23. @5280mark #perfmark @androidbbq #perfmatters 100 Days of GoogleDev ✤ 100

    developer videos over 100 days -- the Google Developers channel is here for you beyond I/O!
  24. @5280mark #perfmark @androidbbq #perfmatters Summary Training wheels coming off -

    tweet on own from now on
  25. [1] Android Design Support Library

  26. ✤ Ian Lake ✤ Developer performance - work faster, more

    features, use Android Design Support Library ✤ TextInputLayout lets you handle input errors with less code ✤ CoordinatorLayout is amazing, helps coordinate motions to actions across widgets
  27. [2] The Magic of LRU Cache

  28. ✤ Colt McAnlis ✤ Cache replacement strategy is a 60

    year old Computer Science field ✤ LRU = Least Recently Used ✤ LRU cache helps you figure out which items to get rid of as memory gets low (eg album thumbnails in a gallery) ✤ Best practice: set memory size to a portion of available memory (available by Android call or even better use device profile), 1/8 is a good starting point ✤ Keep calm and profile on
  29. [3] Google Play Services 7.5

  30. ✤ Magnus Hystten ✤ Topic based subscriptions reduce network usage

    and improve battery life ✤ Reduce GCM messages sent to device ✤ App Invites (performance through downloads!), personal recommendation is better than anonymous corporate messaging
  31. [5] Activity Recognition:Use low power sensors to detect activity No,

    that kind of activity!
  32. ✤ Low power sensors tell you what the user is

    doing ✤ Walking, driving, biking, running ✤ Ever wonder how Google Now knows where you parked? This is how! ✤ Intent based, better performance than a persistant running service ✤ Activity reporting stops when device is still to save on battery
  33. [9] Using LINT for Performance Tips

  34. ✤ Reactive process (consider being proactive) ✤ Static Code Analyzer

    ✤ Correctness, Usability, Security, Accessibility, Performance, Internationalization ✤ Can change specific error levels, maybe change too many views to a warning instead of error because newer devices not an issue
  35. [12] Store Listing Experiments

  36. ✤ Amplify organic user acquisition on Google Play

  37. [13] Get your app found on Google

  38. ✤ Maria Moeva ✤ g.co/searchconsole ✤ “before” Google Analytics ✤

    find out how users got to your app ✤ Verify your deep links are working
  39. [14] Android For Work

  40. ✤ 2014: 250 million Android devices around the world at

    a business ✤ BYOD = Bring your own device ✤ Corporate liable = company bought it for you ✤ I.T. Admin can now group purchase licenses for a company, increase your sales performance
  41. [16] Hidden Cost of Transparency

  42. ✤ Ian Ni-Lewis ✤ beware drop shadows that have opaque

    and transparent parts ✤ use hasOverlappedRendering to make view draw twice as fast ✤ you can profile app to find out where to make faster, but improvements won’t always make the app faster
  43. [20] New APIs in M for Android M for work

    That’s a lot of “for”’s
  44. ✤ Jessica Hummel ✤ Make I.T. admin performance better ✤

    Read only WiFi configurations ✤ COSU = corporate owned single use (think Kiosk) ✤ Can lock a device to single app with a NFC bump
  45. [23] Memory Churn from onDraw()

  46. ✤ Memory churn happens when you allocate a bunch of

    objects, kicking off garbage collection events ✤ Framerate drops, steals battery life, bad! ✤ Drawing libraries are actually wrappers around C++ libraries with destructors/finalizers which are not good for performance ✤ Move allocations out of onDraw, make them static or package scope (even better)
  47. [30] Tool: Strict Mode

  48. ✤ ANR happens after app stops responding for 5 seconds

    ✤ Usually blocking calls like network ✤ In developer mode can turn on strict mode ✤ Screen border flashes red if a blocking call is made ✤ like a runtime version of LINT ✤ Can code a detection map (what to test for and what penalty to apply) ✤ noteSlowCall
  49. [34] Web Bluetooth

  50. ✤ Use the physical web to solve the ladder problem

    ✤ A user shouldn’t have to climb a ladder to view a QR code on a smoke detector ✤ User performance is an important kind of performance
  51. [36] Android Auto Backup for Apps

  52. ✤ Use app backup to improve user performance ✤ Happens

    once a day, only with wifi, power and idle ✤ Uses 25mb portion of Google drive which does not count against user quota
  53. [37] Custom Views and Performance

  54. ✤ 70 standard views in Android ✤ Avoid performance pitfalls

    when making custom views ✤ Never draw things that haven’t changed ✤ Never call invalidate() when you don’t have to ✤ don’t use draw methods that are not hardware accelerated (GPU way better than CPU) ✤ don’t make allocations in onDraw ✤ dual cost from init + garbage collection ✤ when a view is animating onDraw is called 60x per second on UI thread, each has 16ms probably only 8 after you remove overhead
  55. [43] Android Audio Latency

  56. ✤ Glenn Kasten ✤ Really long chicken crossing the road

    analogy ✤ If Kernel isn’t timely you will get popcorn (its a sound) ✤ tempting to make larger buffers to fix problems but better to systrace profile and fix root cause in kernel
  57. [44] Batching Background Work until later

  58. ✤ Be part of a group when wasting power ✤

    Don’t use exact alarms ✤ SyncAdapter gives you network connectivity checks and automatic retries ✤ Share the cost of the battery
  59. [51] Smaller Pixel Formats

  60. ✤ Dalvik’s Android garbage collector is non compacting ✤ means

    no shuffling of items when something too large for available space comes in, kicks off GC ✤ Bitmaps are largest allocations in app ✤ Use BitmapOptions.config to use different compression types for big wins in memory residency trading off for some CPU usage
  61. [57] Memory Profiling 101

  62. ✤ Alex Danilo ✤ Heap Viewer in DDMS ✤ how

    much memory in heap ✤ update heap button starts recording ✤ heap tab has display ✤ click cause GC to force an update ✤ see what types of objects your app has allocated
  63. [58] Performance Tuning Lifecycle

  64. ✤ Joanna Smith ✤ doesn’t like weird man smells in

    the office ✤ 3 steps: Gather, Insight, Action ✤ Rinse and repeat
  65. [59] Smaller PNG Files

  66. ✤ ScriptPNG can help you find sweet spot between compression

    and visual quality ✤ If you don’t need transparency - JPEG ✤ You can separate alpha channel and use 2 JPEGs to take advantage of lossy compression ✤ WebP works on API 17 and above ✤ Data compression helps with data transfer not memory residency, so this video is kind of a filler
  67. [60] Pre-scaling Bitmaps

  68. ✤ createScaledBitmap() requires image to be loaded and decoded ✤

    inSampleSize is very fast, reads every other pixel for 2, can use with any power of 2 ✤ Perf trick - use both! Get almost right size with inSampleSize then fine tune with createScaledBitmap ✤ Since existing libraries already do this (Glide and Picasso) use these proven libraries for production code
  69. [61] Reusing Bitmaps

  70. ✤ Better way to use temporarily allocated bitmaps to escape

    performance concerns ✤ Bitmaps represent largest contiguous blocks of memory in your heaps, can lead to contention and GC ✤ Use object pools ✤ use inBitmap property, but all images must be same size ✤ Again, Glide library does this for you and just use library
  71. [63] Tools not rules

  72. ✤ You can’t always trust rules on the internet ✤

    Instead profile with tools then adjust ✤ Unit test, espresso, monkeyrunner ✤ focus on problems not prescriptions
  73. [65] Fun with ArrayMaps

  74. ✤ Many maps use large arrays that are sparsely populated

    to avoid collisons ✤ ArrayMap for Android uses two small arrays, 2nd array has location hashes for 1st array ✤ If 100’s of items with frequent access use ArrayMap otherwise HashMap ✤ Optimizing performance is a constant trade off, there is no silver bullet
  75. [71] Beware Auto-boxing

  76. ✤ Small things can lead to big problems ✤ generic

    collections like java.lang.Integer are not primitives ✤ auto boxing converts from object type to primitive ✤ requires more performance overhead to get underlying value ✤ Allocation Tracker and traceview can find this problem ✤ Colt’s got 99 problems joke
  77. [79] SparseArray Family Ties

  78. ✤ SparseArrays are like ArrayMaps, using 2 tightly packed arrays

    instead of 1 ✤ Key object is always primitive, not generic ✤ Have to index traverse ✤ Use the right container for the right memory profile
  79. [86] The price of ENUMs

  80. ✤ Most common question Colt gets is about ENUMs ✤

    The previously pictured web page from 2009 caused much confusion ✤ Core platform team on Android does not use ENUMs ✤ @IntDef annotation will optimize for you but … ✤ Long story short, watch out for Gremlins and use ProGuard and any ENUM problems will go away on their own
  81. [89] Docker and Containers: Coffee with a Googler meets Brian

    Dorsey Longest title so far!
  82. ✤ developer efficiency and operation efficiency, let you spend more

    time on building stuff instead of packaging it ✤ Containers are built on Linux Kernel and encapsulate your system (file and processor) ✤ Check out Docker and Kubernetes minecraft server blog posts
  83. [90]Developing for Android Marshmallow

  84. ✤ Rich Hyndman ✤ API level 23 is for Developer

    Preview 3 and release ✤ Can test doze with ADB commands ✤ $ adb shell dumpsys battery unplug ✤ Can avoid auto backup for apps targeting M and above by using “getnobackup” folder — privacy performance?
  85. [91]Introducing Bar Code and QR detection in Google Vision APIs

  86. ✤ Laurence Moroney ✤ QR codes compact data and are

    high performance storage containers ✤ Laurence not to be confused with this L.M.
  87. [93]Double Layout Taxation

  88. ✤ When using fancy features on view layouts you might

    be getting yourself into trouble ✤ Don’t want the layout phase of the rendering pipeline to trigger again ✤ Expensive cascade of layout recalculations ✤ GridLayout is better than RelativeLayout from a performance perspective ✤ SysTrace tool can be used to find problems in measure and layout that might lead to frame rate issues ✤ Hierarchy Viewer can be used to find excessive depth
  89. [100]Trimming and Sharing Memory

  90. ✤ Each running app shares resources ✤ Even when in

    background app can keep state information, graphic resources and heap objects ✤ onTrimMemory callback has trim level 1-100, since ICS ✤ allows you to free up memory to avoid getting killed, reactively ✤ to be proactive for low memory situations use isLowRamDevice() (true if under 512MB), can gate access to certain features
  91. @5280mark #perfmark @androidbbq #perfmatters Summary “Word Clouds are awesome”

  92. @5280mark #perfmark @androidbbq #perfmatters Other Perf Sessions at #BABBQ15 ✤

    2PM today, same room - Android Internal Library Dependency Management with Kelly Shuster ✤ 4PM today, Keynote room - Performant Threading For the Sophisticated BBQr with Colt McAnlis ✤ 9:30AM tomorrow, Keynote room - Android for Java Developers with Chet Haase ✤ 10AM tomorrow, room 1 - Using the NDK Performantly with Daniel Gilpin ✤ 12:30PM tomorrow, Keynote room - Tales of Optimizing for Android Wear with Michael Kwan ✤ 2:30PM tomorrow, Keynote room - Building battery efficient apps with Ran Nachmany ✤ 3PM tomorrow, room 1 - Advanced Android Espresso with Chiu-Ki Chan
  93. None
  94. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  95. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  96. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  97. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  98. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  99. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com #BABBQ15
  100. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  101. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  102. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/r/mscheel ($25 travel credit from me) #BABBQ15
  103. @5280mark #perfmark @androidbbq #perfmatters Follow up with Mark ✤ @5280mark

    ✤ github.com/mscheel ✤ Open Source contributions to Google Glass and Square ✤ stackoverflow.com/mscheel ✤ speakerdeck.com/mscheel ✤ These slides are available now! ✤ lanyrd.com/mscheel ✤ November 20, 2015: droidcon.fr, Paris, France ✤ December 3, 2015: AnDevCon, Santa Clara, CA (Discount code SCHEEL good for $200 off) ✤ meetup.com/gdg-denver ✤ Visit Denver and speak! You can do it. ✤ www.digitalconstruction.com ✤ www.itriagehealth.com ✤ airbnb.com/c/mscheel ($20 travel credit from me) #BABBQ15
  104. October 22, 2015 High Performance Android Mark Scheel (@5280mark) •

    Big Android BBQ • #perfmark #perfmatters
  105. ✤ Hurst Conference Center, Hurst TX ✤ Big Android BBQ

    ✤ October 22, 2015, 1PM, room 3