preface

Performance optimization into every programmer development path, if you want to get ahead, different, you really need to work to study the performance optimization of Android, for example, from optimization application startup, UI loading, to memory, CPU, GPU, IO, and power consumption, etc., when you do the optimization on a, Also once like me, a confused, scratching their heads, and even can not find method, and then see a lot of articles, finally to remember the way some people digestion method, just feel have learned, in fact I don’t think so now, I think the performance optimization must have a fixed thinking framework, let our spontaneous to discover problems, then solve the problem, Only by doing our own discovery can we be different from others and truly master performance optimization, right? Let’s take a look at the underlying logic of performance optimization with me.

Take a look at the Android architecture

Remember this picture? I remember when I first learned Android, the teacher took this picture, and even said that until now, I could understand this picture more deeply. Now LET me reintroduce this picture, maybe it will give you a different perspective. Have you ever noticed that the entire Android system is only divided into two parts, Linux + Android virtual machine, and the rest of the system is not running on this product? (Of course some people will say, isn’t the virtual machine also running on Linux? A. Yes.) If you don’t understand, allow me to draw a picture so you might understand what I’m saying. Please look at:

Programs A and B are running in A virtual machine, and Java needs to interact with Native by using JNI, JNI and C and C++ to call each other. Eventually C interacts with the Linux kernel. From the figure above, if you want to get to the point, there are actually two modules, right? One is Linux and the other is Android virtual machine. Going back to optimization, does that mean we only need to do two things, one is to optimize Linux and one is to optimize the virtual machine? But I really want to tell you that performance optimization is really about one thing at the end of the day, running time optimization for Android on Linux, and that’s the basic underlying logic that we found.

The nature of the underlying logic

Let’s optimize the Android runtime based on Linux. It’s too abstract. If you were specific, what would you come up with?

Hardware point of view

From the point of view of hardware, whether Linux or Android running, in fact, ultimately involved in the use of hardware resources, does that say, how to achieve a reasonable use of hardware resources, is what we should do? I think so. First of all, you should know that the most important resources in hardware resources are computing resources and storage resources.

  • Computing resources are mainly CPU and GPU. For example, we will consider CPU usage as the optimization standard
  • Storage resources are mainly virtual memory and physical memory (disk), such as memory usage, disk usage, etc

How do you use it?

  • For example, the current CPU is multi-core, can use many cores, not one
  • For example, running with 12GB of memory, can we consider sacrificing some memory to improve performance? Right. Are you saying that Google Chrome can take up 7 or 8 gigabytes of memory? Haha, because Google likes to trade space for performance.

Simple summary:

  • Use CPU resources properly
  • Manage memory resources properly

As for how to do more detailed, this is for you to explore.

The software point of view

In terms of software, it’s the application software that we develop. The operating system manages everything except computing resources and memory resources through IO. So the essence of software is IO, in and out. As our software in the system is a process, to create/destroy, with each thread in the process, create/destroyed, one by one in the thread object, creation/destruction of each method in an object, creation/destruction of one member variable and a local variable in a method, create/destroyed. Have you figured out where you want to go? Here’s how:

  • Optimize the process
  • Optimization of thread
  • Optimized object
  • An optimization method
  • Optimization variables

That’s the underlying logic we’re looking for, isn’t it? To solve any problem, I think there should be a reasonable thinking framework, so as to get twice the result with half the effort, there is a track to follow.

conclusion

The space is not long, I talked about the performance optimization of the profound understanding, maybe say out you understand, yes, we all understand, come on, you are the most fat.