From optimizations to Machine Learning: interview with the author of Android High Performance Programming
Almost a year ago, Android High Performance Programming was released . Cool book - but requiring comment. Soon, the author will fly to Russia at the Mobius 2017 Moscow conference , and you can chat with him live. To pass the wait, let's talk with Enrique in the format of a habro interview. Java or Kotlin? How to write fast code? Can Tensorflow and other machine learning be used in a mobile application? Urgently press the "read more" button! ⇩
So, visiting us Enrique López Mañas (Enrique Lopez Manyas) is an independent IT consultant and developer, Android Android Developer Expert. Engaged in mobile technology and programming for more than 10 years, one of the ten most active members of the Java Open Source community in Germany. Recently, I’ve gotten sick with Big Data and ML-technologies, which we will talk about briefly too.

- There are many different recommendations for optimizing Android applications. Some relate to the code, others relate not only to the Android platform. What do you think is the most common mistake?
Enrique Manyas:Android developers are more focused on the framework than on the language. And now, after the active development of Kotlin, they do it even more often than before. According to my feelings, most errors are laid at the code level. And it is here that there is a large space for various improvements. An example is memory leaks.
- Do you have any favorite setting in the compiler or IDE that you could recommend setting “by default”?
Enrique Manyas: First of all, this is Dracula mode. I can’t work with a bright screen - my eyes get tired right away.
In addition, there are a couple more tricks. You can exclude the temp and build directories from the search. This will immediately save a lot of time.
Installing “Constant Conditions & Exceptions” along with strict Error and Nullable settings is a good starting point to get rid of bugs. And semantic highlighting helps you work more productively.
- Do you have any favorite utility? Lint debugger or something like gfxinfo, systrace?
Enrique Manyas: Lint is for everyday use. I like SourceTree. Not only for visualization of brand and history, but also for basic operations (add, commit, diff, etc.).
I also found that working with the console is more efficient. And the entire Android Performance Profiling Tools kit is useful when it comes to debugging. I think that many people underestimate battery profiling in vain.
- I was very surprised to learn that ENUMs on Android take up much more memory than static constants. Can you surprise with anything else?
Enrique Manyas: This may come as a surprise to you: when you build your layout and add it to activity using the Activity.setContentView () method, many other views are also added to the hierarchy to create the desired UI. The owner of the view (DecorView), as a rule, is not needed, since it is blocked by your own layout. You can get rid of it and increase productivity.
- Can you split performance improvement tips into groups? Something like: memory leaks, multithreading, layout layout, networking / data prefetching ...
Enrique Manyas:In my book, I divided recommendations for optimizing performance into different categories. They can be taken as a basis. Creating a layout and building effective representations is one of the groups. Memory (including, but not limited to leaks, JVM, JIT, best practices), multi-threading in Android, networking, security. You can end this list with a battery.
- Not for hype. Your preferences are simply interesting: Java / Kotlin, Kotlin or pure Java. What do you prefer for Android development and why?
Enrique Manyas:Java was born in 1995. After that, several versions were released in which all the initial features were built up and improved. Now we have the eighth version. 22 years for a programming language can be considered an eternity, given how technology is developing now. And at the moment, some of its flags are difficult to ignore. As a developer, I often experiment with different languages. Scala is the most suitable example of how a language can solve some problems with Java flags. The turning point was when I saw Swift in action.
Android natively supports the full range of Java 7 features, and Java 8 only partially. And this does not add points to him in comparison with other platforms. However, this gap is able to fill Kotlin.
Kotlin is a modern language (version 1.0 was only released in February 2016). His main task was not only to close the flaws of Java, as Scala does, but also to solve some of the current problem points (for example, compilation speed). If we talk about my preferences, then for Android it is Kotlin. Unfortunately, in the real world there are many such things as legacy-code, deadlines ... Therefore, it is not always possible to make a full choice.
- One of the official recommendations is the choice of static instead of virtual. In this case, the calls will be 15-20% faster. But static classes are poorly suited for testing and for subsequent architectural changes. It turns out that static is not at all evil when it comes to Android development?
Enrique Manyas:The idea of using static is based on the fact that if your function cannot change an object, then you can make it static, since it does not change the internal state. This also affects execution speed.
- If I have some kind of regular mobile application (not a game or some kind of application with my own graphics). Should I somehow care about 60 FPS support?
Enrique Manyas:You should always achieve a rendering speed of 60 FPS in your mobile application. This means that the screen should be updated at a frequency of 60 times per second or every 16.6667 ms. Complexity can be caused by drawing the hierarchy too often - that is, a large number of CPU cycles. There are several things that we must adhere to, and the refresh rate is just one of them.
- The film “Sphere” showed the opportunity to find any person on earth using a social network. As for me, this scenario was relevant for the two thousandth year. Do you think it is possible to train cars using a social network? Can you tell us something about interesting ways to train NN with ML or what we can get in the future?
Enrique Manyas:I am delighted with those artistic elements that are produced, for example, by the Magenta framework. ML and NN have always been focused on practical tasks such as image recognition. Now they are starting to cope with tasks that were previously only possible for people. In some experiments (here I recommend that you read the book “Homo Deus: A Brief History of Tomorrow” by Yuval Noah Harari), many people cannot distinguish music created by a machine from music written by a person. The moment when the machine can pass the Turing test in the field of artistic activity can be safely called the onset of the singularity.
- How far are we now from the moment when programming for mobile devices will become as simple as HTML? What do you think of applications that are entirely intent or use cloud services? About that way of creating applications when a developer simply combines several services and gets a ready-made application. Sometimes there are applications that 80% consist of libraries, and only the remaining 20% is the code. How can moving to the cloud affect mobile app performance?
Enrique Manyas:As new capabilities and requirements emerge, as well as hardware capacities increase, the development process becomes more complex. Although, as was said, software companies do their job pretty well (here I think primarily about IntelliJ and their first-class tools).
- Machine learning is in most cases associated with image recognition and intellectual learning. However, its potential is much wider. Which scenarios do you find more suitable for Tensorflow’s mobile capabilities?
Enrique Manyas:Using TensorFlow on mobile devices makes sense if you want to get an interactive effect instead of sending the data necessary for processing through the REST API somewhere else. The main examples that Google provides are images. And in TensorFlow, it makes sense when image files are large. Otherwise, they have to be sent for processing (and received back) via the Internet - and this slows down the work with them. If you can process them on a mobile device, it will be more efficient.
But there are also other examples. Think about translations in real time. You probably would like to process everything locally, instead of sending information to the server. Or the creation of music and artwork, as Magenta can already do. ML is already igniting now and, of course, will bring many new features in the near future.
If you are eager to learn more about working with TensorFlow, come listen to Enrique Manyas TensorFlow for mobile devs report at our Mobius 2017 Moscow conference , which will be held in early November. In addition, you will probably be interested in reports of other speakers about mobile development, including:
- How to become a GPU engineer in an hour (Andrey Volodin, Prisma AI)
- We write Java friendly Kotlin-code (Sergey Ryabov, Independent)
- Application size optimization (Dmitry Kurkin, Mail.Ru)