美文网首页
iOS启动优化

iOS启动优化

作者: 蓝天白云_Sam | 来源:发表于2020-12-22 20:24 被阅读0次

https://blog.csdn.net/langzxz/article/details/103808714
load方法耗时测量 开源工具: https://github.com/binzi56/A0PreMainTime
https://zhuanlan.zhihu.com/p/196788030?utm_source=wechat_session

美团外卖iOS App冷启动治理

https://www.jianshu.com/p/035005914510
https://www.jianshu.com/p/b19cd03eea68

高德APP启动耗时剖析与优化实践(iOS篇)

启动优化项

  • 检查并减少getObjectForKeySync和getDataForKeySync的调用
getObjectForKeySync:,kLocalConfigDictionary_00000000

getObjectForKeySync:,kWnsConfigFile

getObjectForKeySync:,kLocalConfigDictionary_2106246804

getObjectForKeySync:,kWSResItemList

getDataForKeySync:,WSKTVMainPageVC.dataModel_2106246804

getDataForKeySync:,kCommonConfigDataKey_RecommandSonglist

getDataForKeySync:,kCommonConfigDataKey_LanguageHotSongList_5

getDataForKeySync:,kCommonConfigDataKey_RecommendCategory

getDataForKeySync:,kDataKey_KTV_Category_UserAddCategory_uid2106246804

getDataForKeySync:,WSLocalDownloadMgr.dataModel_2106246804

getDataForKeySync:,kLocalDownloadedAccompany_uid2106246804

getDataForKeySync:,kLocalDownloadedAccompany_all

getDataForKeySync:,kLocalDownloadingAccompany_uid2106246804

getDataForKeySync:,kLocalDownloadingAccompany_all

getDataForKeySync:,kCommonConfigDataKey_UserInfo_2106246804

getObjectForKeySync:,kABTestConfigDictionary

getDataForKeySync:,userShieldedList_2106246804

getObjectForKeySync:,wesing.tips.get_all_config

getDataForKeySync:,kProductUploadTaskUID_uid2106246804
  • 检查并减少 NSUserDefaults的调用
    rb "-[NSUserDefaults(NSUserDefaults)\ [a-zA-Z:]+ForKey:" -G 1 -C "po [NSString stringWithFormat:@"objForKey:%@", arg3]" rb "-\[NSUserDefaults\(NSUserDefaults\)\ [a-zA-Z:]+forKey:" -G 1 -C "po [NSString stringWithFormat:@\"setObjForKey:%@\",arg3]"

1. 启动优化项

1.1 NSUserDefaults 优化

  1. Hook NSUserDefaultsxxxForKeysetXXX:forKey系列函数,排查频繁读写的设置项
userLanguage,objectForKey:,60
AppleLanguages,objectForKey:,60
AppsFlyerSearchAdsAttribution,dictionaryForKey:,8
sdk.gnl.iap.log.unsentDatas,objectForKey:,6
UserDefaults_LastProvinceID,objectForKey:,5
AppsFlyerFirstLaunchDate,stringForKey:,4
AppsFlyerLastSessionDuration,doubleForKey:,4
AppsFlyerInstallTimestamp,stringForKey:,4
AppsFlyerInstallDate,stringForKey:,4
AppsFlyerLastVersion,stringForKey:,4
AppsFlyerReInstallCounter,stringForKey:,4
ITPManualPrevalentResource,stringForKey:,4
oneLinkVersion,stringForKey:,4
UserDefaults_LastCountryID,objectForKey:,4
AppsFlyerBackupInfo,dictionaryForKey:,4
UIPreferredContentSizeCategoryName,stringForKey:,4
AppsFlyerDate3,stringForKey:,4
  1. 优化userLanguageAppleLanguages的读写:从内存读
  2. Hook synchronize,延迟写文件(延迟2s),并提供强制写文件接口:synchronizeForce

2. 删除无用代码

2.1 fui删除无用代码

注意,安装fui的时候,需要加-n选项

sudo gem install -n /usr/local/bin fui

https://github.com/dblock/fui
fui --path=/Users/sammylan/Documents/Dev/WeSing_Release/QQKSong delete --perform --prompt

2.2 删除引用的代码

通过对Mach-O文件的了解,可以知道__TEXT:__objc_methname:中包含了代码中的所有方法,而__DATA__objc_selrefs中则包含了所有被使用的方法的引用,通过取两个集合的差集就可以得到所有未被使用的代码

 otool -v -s __DATA __objc_selrefs   /Users/sammylan/Documents/MyDoc/FindUnusedCode/QQKSong

2.3 AppCode ->Code -> Inspect Code

System Trace

didFinishLaunching 耗时

image.png
image.png

打点

include <sys/kdebug_signpost.h>

kdebug_signpost_start(code,arg1,arg2,arg3,arg4)
kdebug_signpost_end(code,arg1,arg2,arg3,arg4)

问题列表

1. WNSProtocolBase unpack频繁打日志

if (self.isInternalBuild) {
   WNS_LOG_INFO(@"protocol comannd: %@  response: %@\n\n", self.command, self.rspObject);
}

解决方案:业务层isInternalBuild不要设为YES

image.png

FLEXMethod examine

image.png

HippyBundleUpdateManager

image.png

优化项

-[KSAppDelegate application:didFinishLaunchingWithOptions:]

image.png
  • -[UIApplication beginReceivingRemoteControlEvents] 去掉调用
  • [self updateUserAgentWeSing] web侧使用的UserAgent不需要创建WKWebView构建

-[KSAppDelegate(ThirdParty) initWNSModule]

image.png
  • Wns侧优化
  • 加载Wns配置耗时:

-[KSAppDelegate enterMainUIWithLaunchOptions:]

[WSHippyBundleUpdateManager sharedInstance]_block_invoke

移除- (void)LogInSucess[WSHippyBundleUpdateManager sharedInstance];的调用

image.png

疑问

mach_msg_trap

image.png

WnsUniversalSDK::setLoginType(WnsLoginType)

image.png

Wns setAppInfo

image.png
image.png

WnsConfigMgr 读写数据库

WnsConfigMgr

相关文章

网友评论

      本文标题:iOS启动优化

      本文链接:https://www.haomeiwen.com/subject/nkvbvktx.html