iOS启动时间慢 [英] iOS slow startup time

查看:156
本文介绍了iOS启动时间慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Swift中有项目,当我使用DYLD_PRINT_STATISTICS进行测量时,我可以看到1.0秒的预启动时间,其中70%是动态库链接。

I have project in Swift and when I measure with DYLD_PRINT_STATISTICS I can see 1.0 second pre-init time, where 70% is dynamic libraries linking.

有没有干净安全的方法来处理这个问题?

Are there any clean and safe ways of dealing with this problem?

推荐答案

根据Apple的WWDC 2016年会议优化应用启动时间,无论其大小如何,都有大量动态链接库大大减慢了应用启动时间。

According to Apple's WWDC 2016 Session on Optimizing App Startup Time, regardless of their size, having a large number of dynamically linked libraries slows down app launch time dramatically.

要解决此问题,可以将多个动态库合并到一个库中。如果它们已经静态库,那么可以使用libtool来组合它们,使用这个SO答案。但是,如果它们不是静态的,那么要组合它们,必须能够访问它们的源代码。如果源代码是可访问的,那么将代码从一个库直接复制到另一个库中,并使用生成的库就足够了。

To fix this, several dynamic libraries can be merged into a single library. If they are already static libraries, then libtool can be used to combine them, using the command from this SO answer. However, if they are not static, then to combine them, one must have access to their source code. If the source code is accessible, then literally copying the code from one library into another, and using the resulting library, will suffice.

当然,将不同的库合并到一个库中单一的从开发人员的角度来看肯定是不方便的。为了解决这个问题,Xcode允许在设置不同的标志(即RELEASE和DEBUG)时链接不同的库,如本论坛所述

Of course, merging disparate libraries into a single one is definitely inconvenient from the developer's perspective. To combat this, Xcode allows for different libraries to be linked when different flags (i.e. RELEASE and DEBUG) are set, as described in this forum.

如果可能,最好合并静态库,因为合并过程远不易出错。 CocoaPods 允许用户在他们的项目中使用静态库

When possible, it's better to merge static libraries, as the merging process is far less error prone. CocoaPods allows users to use static libraries in their projects.

这篇关于iOS启动时间慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆