ARouter icon indicating copy to clipboard operation
ARouter copied to clipboard

避免遍历dexfile获取生成类名,缩短启动时间的建议

Open xns1001 opened this issue 9 years ago • 5 comments

我发现ClassUtils.getFileNameByPackageName这个方法耗时很高,主要是遍历dexfile获取arouter生成class类名这个操作造成的。

我做了实验,在有4个dex,3个生成类的情况下。如果是外部传入生成类名,省去遍历dexfile获取类名这步操作,app的启动时间能缩短100ms左右。虽然这样做会使接入麻烦点。但确实能缩短不少启动时间。

xns1001 avatar May 05 '17 09:05 xns1001

这块确实会有耗时,不过这个问题在于要通过包名拿具体的映射文件,拿之前并不知道有多少个映射文件,因为这个包下有多少映射文件完全由用户打包了多少个模块动态决定的。

zhi1ong avatar May 08 '17 05:05 zhi1ong

这个问题导致了ANR,尤其4.4.x机型,有解决方案么 @zhi1ong

jason0539 avatar Jun 20 '17 08:06 jason0539

anr的包发给我,还有手机型号,我这边的Android 4.4.x 没问题 mail:[email protected]

zhi1ong avatar Jun 22 '17 12:06 zhi1ong

arouter

ClassUtils.getFileNameByPackageName这个方法的耗时占用了 Application.onCreate() 方法耗时的一半, 有优化方法吗?

linsea avatar Jul 18 '19 12:07 linsea

@linsea 用 arouter-register 插件

zhi1ong avatar Jul 19 '19 09:07 zhi1ong