Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

首次安装耗时较长 #1336

Open
chy116449859 opened this issue Jun 27, 2024 · 3 comments
Open

首次安装耗时较长 #1336

chy116449859 opened this issue Jun 27, 2024 · 3 comments

Comments

@chy116449859
Copy link

我们有个Android9的设备,首次安装+启动耗时非常久
installPlugin()方法耗时2.096s,
loadPluginLoaderAndRuntime()耗时10.579s,
getLoadedPlugin()耗时0.003s,
loadPlugin()耗时22.128s,
这个过程中这2个方法为什么耗时这么久?有没有什么优化的建议?

我们也测试了多个其他型号的手机和定制化的设备,表现不一,有的手机比较快,整个流程1-2s,有的手机也有10s左右。
IMG20240627173454

@shifujun
Copy link
Collaborator

既然确实不同手机有快有慢,这个优化肯定要针对不同手机来做了。所以分析这个问题并不容易。可能影响比较大的还是磁盘I/O。如果你定位到具体某个方法确实慢,咱们可以一起考虑下怎么优化,比如之前有优化过加载宿主类的白名单的匹配。

按已有的经验,最有效的手段是预加载。在用户触发任何插件的功能前,提前主动执行完插件的application onCreate。尽可能让插件处于就差显示界面这一步了。如果插件还有什么方法可以提前执行,也要提前做。

@chy116449859
Copy link
Author

我们还在定位更细致的方法耗时,之前有没有其他开发者反馈该类问题呢,是否有借鉴的方法可以分享?

@chy116449859
Copy link
Author

查到该问题的主要耗时在dex->oat上,平均耗时大约26s,在android9上表现非常明显。
查了资料,android10后,new classloader就不会自动执行dex->oat,所以这个耗时明显好转。
android9上我们做了优化后,也带来新的问题,由于没有了oat,一般的代码第一次执行明显变慢,浅层的分析应该是类加载(比如VerifyClass过程)耗时,所以又做了异步提前加载class的优化。 查看外面的文章,有不少文章已经提到这些的优化。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants