Recently, a problem has been encountered, the original 32-bit Android running on the good program, on some 64-bit machine has slowed a lot. Feel strange, so Google for a reason, the reason for the Internet is that most of the use of pointers too much . But why is too much use of pointers causing programs to slow down? Combined with online information, and your own understanding, I think is caused by the following reasons:
(1) Since the 64-bit is one-fold larger than the 32-bit pointer, the addressing space has risen sharply from 2^32 to 2^64, but this poses additional problems. The storage space of a pointer also becomes twice times the original, when doing the pointer operation, for example int*ptr,* (ptr+5), the moving distance also becomes twice times the original.
(2) If the cache size of the CPU is constant, 10k=1024*10byte is assumed. The original pointer only occupies 4byte, the cache can store 2,560 pointers. Now because the pointer occupies a larger space, only 1280 can be stored.
(3) Assuming that the program needs to read the data of a pointer, can be easily divided into two cases: if the data in the cache, then direct pointer to the data operation, if the data is not in the cache, the program needs to look for data from memory and update the cache (this part of the mechanism is not particularly familiar with, let's understand ...) )。
(4) In the above case, if the program memory access is often "jumping" words (for example, not i++, but i+=10), considering that the 64-bit machine pointer length into 32-bit machine twice times, then the move will be slower than before. More seriously, the program will also be more frequent in the cache to find data failure, resulting in the search for data from memory and update the cache, so that the time to read data operations will increase, the program will run a significant decrease in speed.
In summary, if an Android manufacturer in order to cut corners, the CPU upgraded to 64-bit, the cache capacity is not upgraded, and just your program has a lot of discontinuous pointer operations, then the program will run slower (our side of the program running slower 50%). On the other hand, if an Android manufacturer has a conscience, and the CPU is upgraded to 64-bit, the cache capacity is also upgraded, then the program slows down basically does not appear. In both cases, I have encountered on different manufacturers of mobile phones, it is not named. For Android developers, especially the NDK development, still need to consider the memory usage optimization, if there is frequent memory application/release, it is best to use the memory pool and other technologies to avoid.
Resources:
"1" http://www.quora.com/ I-came-to-know-that-a-64-bit-architecture-machine-working-with-a-64-bit-os-works-10-15-slower-than-a-32-bit-os-working-on -the-same-machine-why-is-that
"2" http://android-developers.blogspot.com/2015/07/game-performance-data-oriented.html
Why some programs run on a 64-bit machine is slower than a 32-bit machine