这里说的64bit,32bit并不是指cpu

对于cpu来说64bit比32bit快,甚至更省电这应该已经是共识了,64bit拥有更多的寄存器,更大的位宽,更大的总线,当然更快,比如armv8有31个通用寄存器,位宽64bit,48位的寻址空间,armv7只有15个通用寄存器,位宽32bit,虽然寻址空间不是绝对的32位,但是64bit cpu更快是毋庸置疑的,特别是对大量计算的情况比如图片处理,3d游戏,声音人脸识别等等。
64bit处理器在移动端等越来越主流,ios, android等os都相继支持了64bit cpu。
但为了兼容之前的32bit生态系统,64bit cpu/os都选择了兼容32bit模式,不过以后ios/android会慢慢收紧,往64bit only的方向收紧,ios 11已经不接受32bit应用程序,android也计划在2019年8月开始在生态系统内排出32bit应用程序。
https://android-developers.go...
(需要翻墙)
64-bit support requirement in 2019

Platform support for 64-bit architectures was introduced in Android 5.0. Today, over 40% of Android devices coming online have 64-bit support, while still maintaining 32-bit compatibility. For apps that use native libraries, 64-bit code typically offers significantly better performance, with additional registers and new instructions.

In anticipation of future Android devices that support 64-bit code only, the Play Console will require that new apps and app updates with native libraries provide 64-bit versions in addition to their 32-bit versions. This can be within a single APK or as one of the multiple APKs published.

We are not removing 32-bit support. Google Play will continue to support 32-bit apps and devices. Apps that do not include native code are unaffected.

This change will come into effect in August 2019. We're providing advance notice today to allow plenty of time for developers who don't yet support 64-bit to plan the transition. Stay tuned for a future post in which we'll take an in-depth look at the performance benefits of 64-bit native libraries on Android, and check out the CPUs and Architectures guide of the NDK for more info.

但是现阶段,android os还是32bit/64bit共存的状态。

这里想讨论的或者疑问是在64bit cpu上是android 32bit runtime快还是64bit runtime快?

没有理论依据就是看问题的时候突发奇想,做了如下实验:
通过BitmapFactory的decode函数解码一张3024x4032的色彩较丰富的一张图片,大概6M,循环1000次,分别让测试apk运行在32bit和64bit运行时,然后取解码时间平均值进行比较
1.测试函数BitmapFactory.decode(“/sdcard/pic.jpg”); 执行1000次记录每次的解码时间
2.测试平台sdm845, android 8.1 框架:skia, libjpegturbo
3.查看apk运行时的是64bit还是32bit的方法:
先看你的apk的进程的父亲pid,再看这个父亲是谁zygote或者zygote64就ok了
root 1039 1 1618000 45868 0 0 S zygote
u0_a43 1892 1039 2026088 207828 0 0 S com.android.systemui
u0_a43 2465 1039 1986128 158904 0 0 S com.android.systemui:recents
u0_a149 2733 1039 1839736 46328 0 0 S com.tencent.mobileqq:MSF

测试结果:

32bit runtime解码平均时间:236ms
64bit runtime解码平均时间:246ms

32bit runtime faster?
可能一个实验并不能说明什么问题,有待深入研究。


WalkerXu
95 声望29 粉丝