Book Review: Pro Android Apps Performance Optimization

A few weeks ago, a copy of HervĂ© Guihot’s “Pro Android Apps Performance Optimization” landed on my doorstep. I had been waiting on this book to arrive for months. Having served as a technical reviewer for it back in the fall (disclaimer), I had been given a taste of what was to come. So it was nice to finally get to see it in its final form and to read the entire thing without the pressure of a deadline looming.

Most Android books on the market today provide developers with either a 50,000 foot view of the platform or focus on specific APIs that cater to a niche community such as game developers. “Pro Android Apps Performance Optimization” is a bit different. Its goal is to expand on what you already know and show you how to do things faster and with less memory – information of value to every type of Android project.

“Pro Android Apps Performance Optimization” consists of nine chapters, all of which are targeted at intermediate to advanced skill-level Android developers.

Chapter 1 – Optimizing Java Code – Many books include a “kitchen sink” chapter at the end to wrap up loose ends. Guihot, however, decided to put his right at the front. You’ll find a lot of different topics covered in this chapter, including basic algorithm optimization, Android-specific collection classes, fragmentation, and even SQLite query optimization. The chapter is shorter than I would have expected given the wide range of subject matter. But you’ll find lots of good optimization nuggets in here.

Chapter 2 – Getting Started With the NDK – This is your basic introduction to JNI and the NDK. You may be inclined to skip this chapter if you’ve worked with the NDK before. However, if you’ve never created an Activity or utilized a sensor in native code, I’d advise you not to pass it over. There’s a nice introduction to these sorts of things towards the end of the chapter.

Chapter 3 – Advanced NDK – This is the assembly language chapter, or more specifically the ARM assembly language chapter. There are brief snippets of x86 assembly scattered here and there, but the bulk of the discussion is focused on ARM. The author ends the chapter with a brief discussion on GCC extensions.

Chapter 4 – Using Memory Efficiently – The first half of the chapter is a common sense discussion regarding memory allocation and access optimization. The latter half discusses how to avoid memory leaks, describes the various Java reference types, and ends with a very brief discussion on the various classes and methods you can use to inquire about memory usage. One thing that Guihot mentions in passing but definitely warrants more attention is the Memory Analyzer tool. Download and learn it after reading this chapter. It’s one of the most valuable Android tools to have in your toolbox.

Chapter 5 – Multithreading and Synchronization – This chapter starts off with a quick discussion of Java threads and synchronization. It then introduces some of the Android-specific threading classes. The Java threading coverage here is very, very basic. And in Guihot’s defense, there have been entire books devoted to the topic. One such book, and my favorite, is Allen Holub’s “Taming Java Threads”. It’s a little dated, but it’s still very relevant. Check it out. The chapter ends with a discussion of something I love to ding people on in code reviews – the proper management of an ASyncTask from an Activity.

Chapter 6 – Benchmarking and Profiling – Measuring speed is the focus of this chapter. It begins with a discussion on brute forcing speed measurements and then moves on to using Traceview for profiling execution paths in both Java and native code. The chapter ends somewhat randomly with a discussion of LogCat.

Chapter 7 – Maximizing Battery Life – This chapter begins with a brief discussion of batteries. It explains how capacity is measured and demonstrates how you can find out all sorts of data regarding the state of a device’s battery. The meat of the chapter is devoted to strategies for reducing power consumption in your applications. The topics include better BroadcastReceiver management, network access etiquette, location services, and sensors. A discussion on Alarms and WakeLocks wrap up the chapter.

Chapter 8 – Graphics – I was a little disappointed by this part of the book and I think it was entirely due to the chapter’s title, “Graphics.” I expected to see some tips and tricks for working with Views and Canvases, maybe some general graphics related algorithm optimizations, and perhaps even some discussion on better handling of Drawables (a sometimes sneaky source of memory leaks). None of that is in here. The first half of the chapter is devoted to Activity layouts and layout optimization. The second half is devoted to OpenGL topics like mipmaps, texture compression, and shaders. Despite my disappointment, there’s a lot of good information in this chapter. So don’t get the wrong idea.

Chapter 9 – RenderScript – This chapter is more or less an introduction to RenderScript.

Overall, I think this book has tremendous value. Most of my criticisms revolve around the awkward organization of the book and the way the content flows. Once you get past that, you’ll undoubtedly find a lot of things in here that’ll change your approach to Android coding. The author’s style of writing is very casual. And coming in at 270 pages, which is kind of short for a programming book, it certainly won’t take you long to digest it.

Go snag a copy.

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 62 = 65