
Almost a year ago, the book
Android High Performance Programming was released . The book is cool - but requires comments. Soon the author will fly to Russia for the conference
Mobius 2017 Moscow , and you can talk with him live. To pass the wait, let's communicate with Enrique in a habro-interview format.
Java or Kotlin? How to write fast code? Is it possible to use Tensorflow and other machine learning in a mobile application? Urgently press the "read more" button! ⇩

So, on a visit with us
Enrique López Mañas (Enrique López Mignas) is an independent IT consultant and developer with the title of
Android Google Developer Developer . He has been engaged in mobile technologies and programming for more than 10 years, is among the ten most active members of the Java Open Source community in Germany. Recently, I got sick of Big Data and ML technologies, which we will also briefly discuss now.

')
- There are many different recommendations for optimizing Android applications. Some relate to the code, others do not only apply to the Android platform. What do you think is the most common mistake?Enrique Manias: People developing for Android focus more 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 of the 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, which you would recommend to set the "default"?Enrique Manias: First of all, this is Dracula mode. I can not work with a bright screen - my eyes immediately get tired.
In addition, there are a couple of tricks. You can exclude from the search directory temp and build. This will immediately save a lot of time.
Installing Constant Conditions & Exceptions along with rigorous installations of Error and Nullable is a good starting point to get rid of bugs. A semantic illumination helps to work more productively.
- Do you have any favorite utility? Lint debugger or something like gfxinfo, systrace?Enrique Manias: Lint is for everyday use. I like SourceTree. Not only for visualizing strings and history, but also for basic operations (add, commit, diff, etc.).
I also discovered that it is more efficient to work with the console. And the whole Performance Profiling Tools kit from Android is useful when it comes to debugging. I think that battery profiling is often underestimated in vain.
- I was very surprised to learn that ENUMs on Android occupy much more memory than static constants. Can you surprise with something else?Enrique Manias: This is still a surprise for you: when you build your layout and add it to your 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 overlapped by your own layout. You can get rid of it and improve performance.
- Can you share tips on improving performance into some groups? Something like: memory leaks, multithreading, layout layout, networking / data prefetching ...Enrique Magnias: In my book, I divided the recommendations for optimizing performance into different categories. They can be taken as a basis. Creating a layout and building effective views is one of the groups. Memory (including but not limited to leaks, JVM, JIT, best practices), multi-threading in Android, networking, security. To finish this list, you can work with the battery.
- Not for the sake of HYIP. Your preferences are just interesting: Java / Kotlin, Kotlin or pure Java. What do you prefer for Android development and why?Enrique Magnias: Java was born in 1995. After that, several versions appeared in which all the original features were enhanced and improved. Now we have the eighth version. 22 years for a programming language can be considered as eternity, considering how technologies are developing now. And at the moment, some of his flags are hard 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 it does not add points to it in comparison with other platforms. However, this space is able to fill Kotlin.
Kotlin is a modern language (version 1.0 was released only 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, 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 - the choice of static instead of virtual. In this case, 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, if we talk about the development for Android?Enrique Manias: The idea of ​​preferable use of static is based on the fact that if your function cannot change any object, then you can easily make it static, as it does not change the internal state. This also affects the speed of execution.
- If I have some kind of ordinary mobile application (not a game or some kind of application with my own graphics). Should I be worried about 60 FPS support?Enrique Manias: You should always push for 60 FPS rendering speed in your mobile application. This means that the screen should be updated with a frequency of 60 times per second or every 16.6667 ms. The complexity can be caused by drawing the hierarchy too often - that is, a large number of CPU cycles. There are a few things we need to stick to, and the frequency of updates is just one of them.
- In the film “Sphere”, the opportunity was shown to find any person on earth using a social network. As for me, this scenario was relevant to the commercial year in the two thousandth. 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 Magenta framework, for example, gives out. ML and NN have always focused on practical tasks, such as image recognition. Now they are beginning to cope with tasks that were previously only by people. In some experiments (here I recommend you read the book “Homo Deus: A Brief History of Tomorrow” by Yuval Noi Harari) many people cannot distinguish the music created by the machine from the music written by man. The moment when the machine will be able to pass the Turing test in the field of artistic activity, can be safely called the onset of singularity.
- How far are we now from the moment when programming for mobile devices will be as simple as HTML? What do you think about applications that are entirely intsents or use cloud services? About that method of creating applications, when a developer simply combines several services and gets a ready application. Sometimes there are applications that are 80% made up of libraries, and only the remaining 20% ​​is the code. How can moving to the cloud affect mobile app performance?Enrique Mañas: As new capabilities and requirements become available, as well as increasing the capacity of the hardware, the development process becomes more and more complex. Although, as it was said, software companies do their job quite well (here I think primarily about IntelliJ and their first-class tools).
- Machine learning in most cases is associated with image recognition and intellectual learning. However, its potential is much wider. What scenarios do you think are more suitable for Tensorflow mobile features?Enrique Manias: It makes sense to use TensorFlow on mobile devices if you want to get an interactive effect instead of sending the necessary data for processing through the REST API somewhere else. The main examples provided by Google 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 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 real-time transfers. You probably would like to process everything locally, instead of sending information to the server. Or creating music and artwork, as Magenta can already do. ML is already igniting and, of course, will bring many new opportunities in the near future.
If you are eager to learn more details about working with TensorFlow, come and listen to the report of Enrique Manyas
TensorFlow for mobile devs at our
Mobius 2017 Moscow conference, which will be held in early November. In addition, you will certainly be interested in the reports of other speakers about mobile development, including: